From 0ea2fdf6003eff2d22b3ef1450674337ffe405e8 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 14 Sep 2023 09:35:50 +0100 Subject: [PATCH 1/2] fix: update libp2p interfaces to the latest version --- package.json | 4 +--- src/index.ts | 4 ++-- src/selector.ts | 3 +-- src/utils.ts | 4 ++-- src/validator.ts | 5 ++--- test/index.spec.ts | 2 +- test/selector.spec.ts | 2 +- test/validator.spec.ts | 2 +- 8 files changed, 11 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 5cd2d8b..cc42e3d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 0a9a1f3..85912a4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 diff --git a/src/selector.ts b/src/selector.ts index b89d15b..49e2683 100644 --- a/src/selector.ts +++ b/src/selector.ts @@ -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 diff --git a/src/utils.ts b/src/utils.ts index ae55aef..5deaa0b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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/') diff --git a/src/validator.ts b/src/validator.ts index 27a4d9b..6617286 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -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') @@ -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 { if (marshalledData.byteLength > MAX_RECORD_SIZE) { throw errCode(new Error('record too large'), ERRORS.ERR_RECORD_TOO_LARGE) } diff --git a/test/index.spec.ts b/test/index.spec.ts index 78a2e5e..d9f9f32 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -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) diff --git a/test/selector.spec.ts b/test/selector.spec.ts index 6fe26b9..4122bb8 100644 --- a/test/selector.spec.ts +++ b/test/selector.spec.ts @@ -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) diff --git a/test/validator.spec.ts b/test/validator.spec.ts index d2f5a3b..e274b32 100644 --- a/test/validator.spec.ts +++ b/test/validator.spec.ts @@ -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) From 737a2e12bd2452559ab08194cbd16b51187d8065 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 14 Sep 2023 09:41:41 +0100 Subject: [PATCH 2/2] chore: fix linting --- src/validator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validator.ts b/src/validator.ts index 6617286..7732a0d 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -97,7 +97,7 @@ const validateCborDataMatchesPbData = (entry: IPNSEntry): void => { } } -export async function ipnsValidator (key: Uint8Array, marshalledData: Uint8Array): Promise { +export async function ipnsValidator (key: Uint8Array, marshalledData: Uint8Array): Promise { if (marshalledData.byteLength > MAX_RECORD_SIZE) { throw errCode(new Error('record too large'), ERRORS.ERR_RECORD_TOO_LARGE) }