Skip to content

Commit 4cc5935

Browse files
deps(dev): bump aegir from 37.12.1 to 38.1.7 (libp2p#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](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]>
1 parent 3982918 commit 4cc5935

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
"scripts": {
155155
"clean": "aegir clean",
156156
"lint": "aegir lint",
157-
"dep-check": "aegir dep-check",
157+
"dep-check": "aegir dep-check -i protons",
158158
"test": "aegir test",
159159
"test:node": "aegir test -t node",
160160
"test:chrome": "aegir test -t browser",
@@ -176,7 +176,7 @@
176176
},
177177
"devDependencies": {
178178
"@libp2p/crypto": "^1.0.11",
179-
"aegir": "^37.9.1",
179+
"aegir": "^38.1.7",
180180
"protons": "^6.0.0"
181181
}
182182
}

src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export class Libp2pRecord {
2323
this.timeReceived = timeReceived
2424
}
2525

26-
serialize () {
26+
serialize (): Uint8Array {
2727
return Record.encode(this.prepareSerialize())
2828
}
2929

3030
/**
3131
* Return the object format ready to be given to the protobuf library.
3232
*/
33-
prepareSerialize () {
33+
prepareSerialize (): Record {
3434
return {
3535
key: this.key,
3636
value: this.value,
@@ -41,7 +41,7 @@ export class Libp2pRecord {
4141
/**
4242
* Decode a protobuf encoded record
4343
*/
44-
static deserialize (raw: Uint8Array | Uint8ArrayList) {
44+
static deserialize (raw: Uint8Array | Uint8ArrayList): Libp2pRecord {
4545
const rec = Record.decode(raw)
4646

4747
return new Libp2pRecord(rec.key, rec.value, new Date(rec.timeReceived))
@@ -50,7 +50,7 @@ export class Libp2pRecord {
5050
/**
5151
* Create a record from the raw object returned from the protobuf library
5252
*/
53-
static fromDeserialized (obj: Record) {
53+
static fromDeserialized (obj: Record): Libp2pRecord {
5454
const recvtime = utils.parseRFC3339(obj.timeReceived)
5555

5656
if (obj.key == null) {

src/selectors.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Selectors } from '@libp2p/interface-dht'
55
/**
66
* Select the best record out of the given records
77
*/
8-
export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8Array[]) {
8+
export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8Array[]): number {
99
if (records.length === 0) {
1010
const errMsg = 'No records given'
1111

@@ -41,7 +41,7 @@ export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8A
4141
* Simply returns the first record, as all valid public key
4242
* records are equal
4343
*/
44-
function publickKey (k: Uint8Array, records: Uint8Array[]) {
44+
function publickKey (k: Uint8Array, records: Uint8Array[]): number {
4545
return 0
4646
}
4747

src/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Convert a JavaScript date into an `RFC3339Nano` formatted
33
* string
44
*/
5-
export function toRFC3339 (time: Date) {
5+
export function toRFC3339 (time: Date): string {
66
const year = time.getUTCFullYear()
77
const month = String(time.getUTCMonth() + 1).padStart(2, '0')
88
const day = String(time.getUTCDate()).padStart(2, '0')
@@ -19,7 +19,7 @@ export function toRFC3339 (time: Date) {
1919
* Parses a date string formatted as `RFC3339Nano` into a
2020
* JavaScript Date object
2121
*/
22-
export function parseRFC3339 (time: string) {
22+
export function parseRFC3339 (time: string): Date {
2323
const rfc3339Matcher = new RegExp(
2424
// 2006-01-02T
2525
'(\\d{4})-(\\d{2})-(\\d{2})T' +

src/validators.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
1010
* It runs the needed validators.
1111
* If verification fails the returned Promise will reject with the error.
1212
*/
13-
export function verifyRecord (validators: Validators, record: Libp2pRecord) {
13+
export async function verifyRecord (validators: Validators, record: Libp2pRecord): Promise<void> {
1414
const key = record.key
1515
const keyString = uint8ArrayToString(key)
1616
const parts = keyString.split('/')
@@ -28,7 +28,7 @@ export function verifyRecord (validators: Validators, record: Libp2pRecord) {
2828
throw new CodeError(errMsg, 'ERR_INVALID_RECORD_KEY_TYPE')
2929
}
3030

31-
return validator(key, record.value)
31+
await validator(key, record.value)
3232
}
3333

3434
/**
@@ -40,7 +40,7 @@ export function verifyRecord (validators: Validators, record: Libp2pRecord) {
4040
* @param {Uint8Array} key - A valid key is of the form `'/pk/<keymultihash>'`
4141
* @param {Uint8Array} publicKey - The public key to validate against (protobuf encoded).
4242
*/
43-
const validatePublicKeyRecord = async (key: Uint8Array, publicKey: Uint8Array) => {
43+
const validatePublicKeyRecord = async (key: Uint8Array, publicKey: Uint8Array): Promise<void> => {
4444
if (!(key instanceof Uint8Array)) {
4545
throw new CodeError('"key" must be a Uint8Array', 'ERR_INVALID_RECORD_KEY_NOT_BUFFER')
4646
}

test/validator.spec.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('validator', () => {
6262
})
6363

6464
describe('verifyRecord', () => {
65-
it('calls matching validator', () => {
65+
it('calls matching validator', async () => {
6666
const k = uint8ArrayFromString('/hello/you')
6767
const rec = new Libp2pRecord(k, uint8ArrayFromString('world'), new Date())
6868

@@ -72,10 +72,10 @@ describe('validator', () => {
7272
expect(value).to.eql(uint8ArrayFromString('world'))
7373
}
7474
}
75-
return validator.verifyRecord(validators, rec)
75+
await validator.verifyRecord(validators, rec)
7676
})
7777

78-
it('calls not matching any validator', () => {
78+
it('calls not matching any validator', async () => {
7979
const k = uint8ArrayFromString('/hallo/you')
8080
const rec = new Libp2pRecord(k, uint8ArrayFromString('world'), new Date())
8181

@@ -85,11 +85,10 @@ describe('validator', () => {
8585
expect(value).to.eql(uint8ArrayFromString('world'))
8686
}
8787
}
88-
return expect(
89-
() => validator.verifyRecord(validators, rec)
90-
).to.throw(
91-
/Invalid record keytype/
92-
)
88+
await expect(validator.verifyRecord(validators, rec))
89+
.to.eventually.rejectedWith(
90+
/Invalid record keytype/
91+
)
9392
})
9493
})
9594

@@ -107,7 +106,7 @@ describe('validator', () => {
107106

108107
it('does not error on valid record', async () => {
109108
return await Promise.all(cases.valid.publicKey.map(async (k) => {
110-
return await validator.validators.pk(k, key.public.bytes)
109+
await validator.validators.pk(k, key.public.bytes)
111110
}))
112111
})
113112

@@ -132,7 +131,7 @@ describe('validator', () => {
132131

133132
const hash = await pubKey.hash()
134133
const k = Uint8Array.of(...uint8ArrayFromString('/pk/'), ...hash)
135-
return await validator.validators.pk(k, pubKey.bytes)
134+
await validator.validators.pk(k, pubKey.bytes)
136135
})
137136
})
138137
})

0 commit comments

Comments
 (0)