Skip to content

Commit

Permalink
fix: update libp2p interfaces to the latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Sep 14, 2023
1 parent c51dc2f commit 0ea2fdf
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 15 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@
},
"dependencies": {
"@libp2p/crypto": "^2.0.3",
"@libp2p/interface-dht": "^2.0.0",
"@libp2p/interface-keys": "^1.0.3",
"@libp2p/interface-peer-id": "^2.0.0",
"@libp2p/interface": "^0.1.2",
"@libp2p/logger": "^3.0.2",
"@libp2p/peer-id": "^3.0.2",
"cborg": "^4.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import * as ERRORS from './errors.js'
import { IpnsEntry } from './pb/ipns.js'
import { createCborData, ipnsEntryDataForV1Sig, ipnsEntryDataForV2Sig } from './utils.js'
import type { PrivateKey } from '@libp2p/interface-keys'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PrivateKey } from '@libp2p/interface/keys'
import type { PeerId } from '@libp2p/interface/peer-id'

const log = logger('ipns')
const ID_MULTIHASH_CODE = identity.code
Expand Down
3 changes: 1 addition & 2 deletions src/selector.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { IpnsEntry } from './pb/ipns.js'
import { parseRFC3339 } from './utils.js'
import type { SelectFn } from '@libp2p/interface-dht'

export const ipnsSelector: SelectFn = (key, data) => {
export function ipnsSelector (key: Uint8Array, data: Uint8Array[]): number {
const entries = data.map((buf, index) => ({
entry: IpnsEntry.decode(buf),
index
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import * as ERRORS from './errors.js'
import { IpnsEntry } from './pb/ipns.js'
import type { IPNSEntry, IPNSEntryData } from './index.js'
import type { PublicKey } from '@libp2p/interface-keys'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PublicKey } from '@libp2p/interface/keys'
import type { PeerId } from '@libp2p/interface/peer-id'

const log = logger('ipns:utils')
const IPNS_PREFIX = uint8ArrayFromString('/ipns/')
Expand Down
5 changes: 2 additions & 3 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import * as ERRORS from './errors.js'
import { IpnsEntry } from './pb/ipns.js'
import { parseRFC3339, extractPublicKey, ipnsEntryDataForV2Sig, unmarshal, peerIdFromRoutingKey, parseCborData } from './utils.js'
import type { IPNSEntry } from './index.js'
import type { ValidateFn } from '@libp2p/interface-dht'
import type { PublicKey } from '@libp2p/interface-keys'
import type { PublicKey } from '@libp2p/interface/keys'

const log = logger('ipns:validator')

Expand Down Expand Up @@ -98,7 +97,7 @@ const validateCborDataMatchesPbData = (entry: IPNSEntry): void => {
}
}

export const ipnsValidator: ValidateFn = async (key, marshalledData) => {
export async function ipnsValidator (key: Uint8Array, marshalledData: Uint8Array): Promise<void> {
if (marshalledData.byteLength > MAX_RECORD_SIZE) {
throw errCode(new Error('record too large'), ERRORS.ERR_RECORD_TOO_LARGE)
}
Expand Down
2 changes: 1 addition & 1 deletion test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as ERRORS from '../src/errors.js'
import * as ipns from '../src/index.js'
import { unmarshal, marshal, extractPublicKey, peerIdToRoutingKey } from '../src/utils.js'
import { ipnsValidator } from '../src/validator.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'

describe('ipns', function () {
this.timeout(20 * 1000)
Expand Down
2 changes: 1 addition & 1 deletion test/selector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import * as ipns from '../src/index.js'
import { ipnsSelector } from '../src/selector.js'
import { marshal, peerIdToRoutingKey } from '../src/utils.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'

describe('selector', function () {
this.timeout(20 * 1000)
Expand Down
2 changes: 1 addition & 1 deletion test/validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as ERRORS from '../src/errors.js'
import * as ipns from '../src/index.js'
import { marshal, peerIdToRoutingKey } from '../src/utils.js'
import { ipnsValidator } from '../src/validator.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerId } from '@libp2p/interface/peer-id'

describe('validator', function () {
this.timeout(20 * 1000)
Expand Down

0 comments on commit 0ea2fdf

Please sign in to comment.