diff --git a/packages/compliance-tests/src/peer-id/index.js b/packages/compliance-tests/src/peer-id/index.js index fa20d01ed..cff78a0f3 100644 --- a/packages/compliance-tests/src/peer-id/index.js +++ b/packages/compliance-tests/src/peer-id/index.js @@ -357,10 +357,6 @@ module.exports = (common) => { const peerId2 = factory.createFromB58String(peerId.toB58String()) expect(peerId1).to.deep.equal(peerId2) - - peerId1.toString() - - expect(peerId1).to.deep.equal(peerId2) }) describe('throws on inconsistent data', () => { @@ -382,29 +378,24 @@ module.exports = (common) => { it('missmatch private - public key', async () => { const digest = await k1.public.hash() - expect(() => { - factory.createFromJSON({ - id: digest, - pubKey: k1, - privKey: k2.public - }) // eslint-disable-line no-new - }).to.throw(/inconsistent arguments/) + await expect(factory.createFromJSON({ + id: digest, + pubKey: k1, + privKey: k2.public + })).eventually.be.rejectedWith(/inconsistent arguments/) }) it('missmatch id - private - public key', async () => { const digest = await k1.public.hash() - expect(() => { - factory.createFromJSON({ - id: digest, - pubKey: k1, - privKey: k3.public - }) // eslint-disable-line no-new - }).to.throw(/inconsistent arguments/) + await expect(factory.createFromJSON({ + id: digest, + pubKey: k1, + privKey: k3.public + })).eventually.be.rejectedWith(/inconsistent arguments/) }) it('invalid id', () => { - // @ts-expect-error incorrect constructor arg type - expect(() => factory.createFromJSON('hello world')).to.throw(/invalid id/) + await expect(factory.createFromJSON('hello world')).eventually.be.rejectedWith(/invalid id/) }) }) }) diff --git a/packages/interfaces/src/peer-id/types.d.ts b/packages/interfaces/src/peer-id/types.d.ts index 0c69cc8b4..0e0e31aba 100644 --- a/packages/interfaces/src/peer-id/types.d.ts +++ b/packages/interfaces/src/peer-id/types.d.ts @@ -1,26 +1,26 @@ import type { CID } from 'multiformats/cid' import type { PublicKey, PrivateKey, KeyType } from '../keys/types' -interface PeerIdJSON { +export interface PeerIdJSON { readonly id: string; readonly pubKey?: string; readonly privKey?: string; } -interface CreateOptions { +export interface CreateOptions { bits?: number; keyType?: KeyType; } export interface PeerId { - readonly id: Uint8Array; - privKey: PrivateKey; - pubKey: PublicKey; + readonly id: Uint8Array + privKey: PrivateKey | undefined; + pubKey: PublicKey | undefined; /** * Return the protobuf version of the public key, matching go ipfs formatting */ - marshalPubKey ():Uint8Array; + marshalPubKey: () => Uint8Array | undefined; /** * Return the protobuf version of the private key, matching go ipfs formatting @@ -85,6 +85,11 @@ export interface PeerId { } export interface PeerIdFactory { + /** + * Create a new PeerId. + **/ + new (id: Uint8Array, privKey?: PrivateKey, pubKey?: PublicKey): PeerId; + /** * Create a new PeerId. **/