diff --git a/README.md b/README.md index aad6ad0..c5eb8a9 100644 --- a/README.md +++ b/README.md @@ -9,5 +9,7 @@ In general, updates here should have corrsponding PRs on the DefinitelyTyped rep This following libraries are currently included. Where possible add the relevant DT PRs as there are included - may not be applicable initially if definitions are not expansive enough or fully tested internally. - [blakejs](https://github.com/dcposch/blakejs) -- [bn.js](https://github.com/indutny/bn.js/) [@types PR #26717](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/26717) +- [bn.js](https://github.com/indutny/bn.js) [@types PR #26717](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/26717) - [keccak](https://github.com/cryptocoinjs/keccak) +- [multiaddr](https://github.com/multiformats/js-multiaddr) +- [peer-id](https://github.com/libp2p/js-peer-id) diff --git a/multiaddr/index.d.ts b/multiaddr/index.d.ts new file mode 100644 index 0000000..19d76c7 --- /dev/null +++ b/multiaddr/index.d.ts @@ -0,0 +1,53 @@ +// Type definitions for multiaddr 5.0.0 +// Project: https://github.com/multiformats/js-multiaddr +// Definitions by: Jaco Greeff +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import PeerId from 'peer-id'; + +type Address = { + family: string, + host: string, + port: string +}; + +type Options = Address & { + transport: string +}; + +type Proto = { + code: number, + name: string, + size: number +}; + +type Tuple = [ number, Buffer ]; + +type TupleString = [ number, string ]; + +declare class Multiaddr { + constructor (addr: Multiaddr | Buffer | string); + + static isMultiaddr (addr: Multiaddr): addr is Multiaddr; + static isName (other: Multiaddr): boolean; + static fromNodeAddress (addr: { address: string, port: string }, transport: string): Multiaddr; + + decapsulate (other: Multiaddr): Multiaddr; + encapsulate (other: Multiaddr): Multiaddr; + equals (other: Multiaddr): boolean; + getPeerId (): PeerId; + inspect (): string; + isThinWaistAddress (other?: Multiaddr): boolean; + nodeAddress (): Address; + protos (): Proto[]; + protoCodes (): number[]; + protoNames (): string[]; + stringTuples (): TupleString[]; + tuples (): Tuple[]; + toOptions (): Options; + toString (): string; +} + +export default Multiaddr; diff --git a/multiaddr/multiaddr-tests.ts b/multiaddr/multiaddr-tests.ts new file mode 100644 index 0000000..e69de29 diff --git a/multiaddr/tsconfig.json b/multiaddr/tsconfig.json new file mode 100644 index 0000000..932e246 --- /dev/null +++ b/multiaddr/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "bn.js-tests.ts"] +} diff --git a/multiaddr/tslint.json b/multiaddr/tslint.json new file mode 100644 index 0000000..3db14f8 --- /dev/null +++ b/multiaddr/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }