Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

deps(dev): bump aegir from 37.12.1 to 38.1.7 #84

Merged
merged 3 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})
})