diff --git a/package.json b/package.json index 464667f..b9478bf 100644 --- a/package.json +++ b/package.json @@ -186,7 +186,7 @@ }, "devDependencies": { "@libp2p/peer-id-factory": "^2.0.0", - "aegir": "^38.1.7", + "aegir": "^39.0.10", "protons": "^7.0.2" } } diff --git a/src/index.ts b/src/index.ts index cdfe51e..92697b2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,16 @@ -import NanoDate from 'timestamp-nano' -import { Key } from 'interface-datastore/key' import { unmarshalPrivateKey } from '@libp2p/crypto/keys' +import { logger } from '@libp2p/logger' import errCode from 'err-code' +import { Key } from 'interface-datastore/key' import { base32upper } from 'multiformats/bases/base32' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { logger } from '@libp2p/logger' -import { createCborData, ipnsEntryDataForV1Sig, ipnsEntryDataForV2Sig } from './utils.js' -import * as ERRORS from './errors.js' -import { equals as uint8ArrayEquals } from 'uint8arrays/equals' import * as Digest from 'multiformats/hashes/digest' import { identity } from 'multiformats/hashes/identity' +import NanoDate from 'timestamp-nano' +import { equals as uint8ArrayEquals } from 'uint8arrays/equals' +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' @@ -64,7 +64,7 @@ export const create = async (peerId: PeerId, value: Uint8Array, seq: number | bi const [ms, ns] = lifetime.toString().split('.') const lifetimeNs = (BigInt(ms) * BigInt(100000)) + BigInt(ns ?? '0') - return await _create(peerId, value, seq, validityType, expirationDate, lifetimeNs) + return _create(peerId, value, seq, validityType, expirationDate, lifetimeNs) } /** @@ -83,7 +83,7 @@ export const createWithExpiration = async (peerId: PeerId, value: Uint8Array, se const ttlMs = expirationDate.toDate().getTime() - Date.now() const ttlNs = (BigInt(ttlMs) * BigInt(100000)) + BigInt(expirationDate.getNano()) - return await _create(peerId, value, seq, validityType, expirationDate, ttlNs) + return _create(peerId, value, seq, validityType, expirationDate, ttlNs) } const _create = async (peerId: PeerId, value: Uint8Array, seq: number | bigint, validityType: IpnsEntry.ValidityType, expirationDate: NanoDate, ttl: bigint): Promise => { diff --git a/src/utils.ts b/src/utils.ts index 0d049f9..ae55aef 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,15 +1,15 @@ -import errCode from 'err-code' -import type { PeerId } from '@libp2p/interface-peer-id' -import type { IPNSEntry, IPNSEntryData } from './index.js' -import * as ERRORS from './errors.js' import { unmarshalPublicKey } from '@libp2p/crypto/keys' -import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id' import { logger } from '@libp2p/logger' -import { IpnsEntry } from './pb/ipns.js' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { concat as uint8ArrayConcat } from 'uint8arrays/concat' +import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id' import * as cborg from 'cborg' +import errCode from 'err-code' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' +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' const log = logger('ipns:utils') const IPNS_PREFIX = uint8ArrayFromString('/ipns/') diff --git a/src/validator.ts b/src/validator.ts index 7b7136c..7d78133 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -1,13 +1,13 @@ +import { logger } from '@libp2p/logger' import errCode from 'err-code' -import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { equals as uint8ArrayEquals } from 'uint8arrays/equals' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' +import * as ERRORS from './errors.js' import { IpnsEntry } from './pb/ipns.js' import { parseRFC3339, extractPublicKey, ipnsEntryDataForV2Sig, unmarshal, peerIdFromRoutingKey, parseCborData } from './utils.js' -import * as ERRORS from './errors.js' import type { IPNSEntry } from './index.js' -import type { PublicKey } from '@libp2p/interface-keys' import type { ValidateFn } from '@libp2p/interface-dht' -import { logger } from '@libp2p/logger' +import type { PublicKey } from '@libp2p/interface-keys' const log = logger('ipns:validator') diff --git a/test/index.spec.ts b/test/index.spec.ts index eafca97..78a2e5e 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -1,17 +1,17 @@ /* eslint-env mocha */ +import { randomBytes } from '@libp2p/crypto' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromKeys, peerIdFromString } from '@libp2p/peer-id' +import { createEd25519PeerId } from '@libp2p/peer-id-factory' import { expect } from 'aegir/chai' import { base58btc } from 'multiformats/bases/base58' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { peerIdFromKeys, peerIdFromString } from '@libp2p/peer-id' -import { generateKeyPair } from '@libp2p/crypto/keys' -import { randomBytes } from '@libp2p/crypto' -import * as ipns from '../src/index.js' import * as ERRORS from '../src/errors.js' -import type { PeerId } from '@libp2p/interface-peer-id' +import * as ipns from '../src/index.js' import { unmarshal, marshal, extractPublicKey, peerIdToRoutingKey } from '../src/utils.js' import { ipnsValidator } from '../src/validator.js' -import { createEd25519PeerId } from '@libp2p/peer-id-factory' +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 51931bd..6fe26b9 100644 --- a/test/selector.spec.ts +++ b/test/selector.spec.ts @@ -1,12 +1,12 @@ /* eslint-env mocha */ +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromKeys } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import { peerIdFromKeys } from '@libp2p/peer-id' -import { generateKeyPair } from '@libp2p/crypto/keys' import * as ipns from '../src/index.js' -import { marshal, peerIdToRoutingKey } from '../src/utils.js' import { ipnsSelector } from '../src/selector.js' +import { marshal, peerIdToRoutingKey } from '../src/utils.js' import type { PeerId } from '@libp2p/interface-peer-id' describe('selector', function () { diff --git a/test/validator.spec.ts b/test/validator.spec.ts index fdb7499..8001f45 100644 --- a/test/validator.spec.ts +++ b/test/validator.spec.ts @@ -1,17 +1,17 @@ /* eslint-env mocha */ +import { randomBytes } from '@libp2p/crypto' +import { generateKeyPair } from '@libp2p/crypto/keys' +import { peerIdFromKeys } from '@libp2p/peer-id' import { expect } from 'aegir/chai' import { base58btc } from 'multiformats/bases/base58' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' -import { peerIdFromKeys } from '@libp2p/peer-id' -import { generateKeyPair } from '@libp2p/crypto/keys' -import { randomBytes } from '@libp2p/crypto' -import * as ipns from '../src/index.js' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import * as ERRORS from '../src/errors.js' -import type { PeerId } from '@libp2p/interface-peer-id' +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' describe('validator', function () { this.timeout(20 * 1000)