Last active
August 17, 2021 09:15
-
-
Save joeltg/6a57d06f33d24ab65c0a477c56e0537b to your computer and use it in GitHub Desktop.
TypeScript definition files for miscellaneous Protocol Labs projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export as namespace CID | |
export = CID | |
type Buffer = any | |
interface SerializedCID { | |
codec: string | |
version: number | |
multihash: Buffer | |
} | |
declare class CID { | |
constructor(version: number, codec: string, multihash: Buffer) | |
static isCID(other: any): boolean | |
static validateCID(other: any): void | |
codec: string | |
version: number | |
multihash: Buffer | |
buffer: Buffer | |
prefix: Buffer | |
toV0(): CID | |
toV1(): CID | |
toBaseEncodedString(base?: string): string | |
toJSON(): SerializedCID | |
equals(other: CID): boolean | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="./multiaddr.d.ts" /> | |
/// <reference path="./multihash.d.ts" /> | |
/// <reference path="./cid.d.ts" /> | |
/// <reference path="./libp2p.d.ts" /> | |
/// <reference path="./ipld.d.ts" /> | |
export as namespace ipfs | |
export = IPFS | |
type Callback<T> = (error: Error, result?: T) => void | |
type VoidCallback = (error?: Error) => void | |
declare class IPFS { | |
constructor(options: IPFS.Options) | |
types: IPFS.Types | |
init(options: IPFS.InitOptions, callback: Callback<boolean>) | |
init(callback: Callback<boolean>) | |
preStart(callback: Callback<any>) | |
start(callback?: Callback<any>) | |
stop(callback?: VoidCallback) | |
isOnline(): boolean | |
version(options: any, callback: (error: Error, version: IPFS.Version) => void) | |
version(options: any): Promise<IPFS.Version> | |
version(callback: (error: Error, version: IPFS.Version) => void) | |
version(): Promise<IPFS.Version> | |
id(options: any, callback: (error: Error, version: IPFS.Id) => void) | |
id(options: any): Promise<IPFS.Id> | |
id(callback: (error: Error, version: IPFS.Id) => void) | |
id(): Promise<IPFS.Id> | |
repo: IPFS.RepoAPI | |
bootstrap: any | |
config: any | |
block: any | |
object: IPFS.ObjectAPI | |
dag: IPFS.DagAPI | |
libp2p: libp2p.Node | |
swarm: IPFS.SwarmAPI | |
files: IPFS.FilesAPI | |
bitswap: any | |
// TODO: figure out why just .libp2p doesn't actually work | |
_libp2pNode: libp2p.Node | |
_ipld: IPLD | |
ping(callback: (error: Error) => void) | |
ping(): Promise<void> | |
pubsub: libp2p.PubSubAPI | |
on(event: string, callback: (error?: string) => void): IPFS | |
once(event: string, callback: () => void): IPFS | |
} | |
declare namespace IPFS { | |
export interface Options { | |
init?: boolean | |
start?: boolean | |
EXPERIMENTAL?: any | |
repo?: string | |
config?: any | |
libp2p?: { | |
modules?: { | |
[module: string]: any | |
} | |
config?: { | |
peerDiscovery?: { | |
[id: string]: { enabled: boolean; [prop: string]: any } | |
} | |
dht?: { | |
[property: string]: any | |
} | |
} | |
} | |
relay?: { | |
enabled?: boolean | |
hop?: { | |
enabled?: boolean | |
active?: boolean | |
} | |
} | |
} | |
export interface InitOptions { | |
emptyRepo?: boolean | |
bits?: number | |
log?: Function | |
} | |
export interface Types { | |
Buffer: { | |
from( | |
other: string | number[] | Object | Buffer | ArrayBuffer, | |
format?: string | |
): Buffer | |
} | |
PeerId: libp2p.PeerId | |
PeerInfo: libp2p.PeerInfo | |
multiaddr: Multiaddr | |
multihash: Multihash | |
CID: { new (version: number, codec: string, multihash: Buffer): CID } | |
} | |
export interface Version { | |
version: string | |
repo: string | |
commit: string | |
} | |
export interface Id { | |
id: string | |
publicKey: string | |
addresses: Multiaddr[] | |
agentVersion: string | |
protocolVersion: string | |
} | |
export interface RepoAPI { | |
init(bits: number, empty: boolean, callback: Callback<any>) | |
version(options: any, callback: Callback<any>) | |
version(callback: Callback<any>) | |
gc() | |
path(): string | |
} | |
export type FileContent = Object | Buffer | Blob | string | |
export interface IPFSFile { | |
path: string | |
hash: string | |
size: number | |
content?: FileContent | |
} | |
export interface FilesAPI { | |
createAddStream(options: any, callback: Callback<any>) | |
createAddStream(callback: Callback<any>) | |
createPullStream(options: any): any | |
add(data: FileContent, options: any, callback: Callback<IPFSFile[]>) | |
add(data: FileContent, options: any): Promise<IPFSFile[]> | |
add(data: FileContent, callback: Callback<IPFSFile[]>) | |
add(data: FileContent): Promise<IPFSFile[]> | |
cat(hash: Multihash, callback: Callback<FileContent>) | |
cat(hash: Multihash): Promise<FileContent> | |
cat(hash: string, callback: Callback<FileContent>) | |
cat(hash: string): Promise<FileContent> | |
get(hash: Multihash, callback: Callback<IPFSFile[]>) | |
get(hash: Multihash): Promise<IPFSFile[]> | |
get(hash: string, callback: Callback<IPFSFile[]>) | |
get(hash: string): Promise<IPFSFile[]> | |
getPull(hash: Multihash, callback: Callback<any>) | |
getPull(hash: Multihash): Promise<any> | |
getPull(hash: string, callback: Callback<any>) | |
getPull(hash: string): Promise<any> | |
} | |
export interface PeersOptions { | |
v?: boolean | |
verbose?: boolean | |
} | |
export interface Peer { | |
addr: Multiaddr | |
peer: libp2p.PeerInfo | |
} | |
export interface SwarmAPI { | |
peers(options: PeersOptions, callback: Callback<Peer[]>) | |
peers(options: PeersOptions): Promise<Peer[]> | |
peers(callback: Callback<Peer[]>) | |
peers(): Promise<Peer[]> | |
addrs(callback: Callback<libp2p.PeerInfo[]>) | |
addrs(): Promise<libp2p.PeerInfo[]> | |
localAddrs(callback: Callback<Multiaddr[]>) | |
localAddrs(): Promise<Multiaddr[]> | |
connect(maddr: Multiaddr | string, callback: Callback<any>) | |
connect(maddr: Multiaddr | string): Promise<any> | |
disconnect(maddr: Multiaddr | string, callback: Callback<any>) | |
disconnect(maddr: Multiaddr | string): Promise<any> | |
filters(callback: Callback<void>): never | |
} | |
export type DAGNode = any | |
export type DAGLink = any | |
export type DAGLinkRef = DAGLink | any | |
export type Obj = BufferSource | Object | |
export interface ObjectStat { | |
Hash: Multihash | |
NumLinks: number | |
BlockSize: number | |
LinksSize: number | |
DataSize: number | |
CumulativeSize: number | |
} | |
export interface PutObjectOptions { | |
enc?: any | |
} | |
export interface GetObjectOptions { | |
enc?: any | |
} | |
export interface ObjectPatchAPI { | |
addLink( | |
multihash: Multihash, | |
link: DAGLink, | |
options: GetObjectOptions, | |
callback: Callback<any> | |
) | |
addLink( | |
multihash: Multihash, | |
link: DAGLink, | |
options: GetObjectOptions | |
): Promise<any> | |
addLink(multihash: Multihash, link: DAGLink, callback: Callback<any>) | |
addLink(multihash: Multihash, link: DAGLink): Promise<any> | |
rmLink( | |
multihash: Multihash, | |
linkRef: DAGLinkRef, | |
options: GetObjectOptions, | |
callback: Callback<any> | |
) | |
rmLink( | |
multihash: Multihash, | |
linkRef: DAGLinkRef, | |
options: GetObjectOptions | |
): Promise<any> | |
rmLink(multihash: Multihash, linkRef: DAGLinkRef, callback: Callback<any>) | |
rmLink(multihash: Multihash, linkRef: DAGLinkRef): Promise<any> | |
appendData( | |
multihash: Multihash, | |
data: any, | |
options: GetObjectOptions, | |
callback: Callback<any> | |
) | |
appendData( | |
multihash: Multihash, | |
data: any, | |
options: GetObjectOptions | |
): Promise<any> | |
appendData(multihash: Multihash, data: any, callback: Callback<any>) | |
appendData(multihash: Multihash, data: any): Promise<any> | |
setData( | |
multihash: Multihash, | |
data: any, | |
options: GetObjectOptions, | |
callback: Callback<any> | |
) | |
setData( | |
multihash: Multihash, | |
data: any, | |
options: GetObjectOptions | |
): Promise<any> | |
setData(multihash: Multihash, data: any, callback: Callback<any>) | |
setData(multihash: Multihash, data: any): Promise<any> | |
} | |
export interface ObjectAPI { | |
"new"(template: "unixfs-dir", callback: Callback<DAGNode>) | |
"new"(callback: Callback<DAGNode>) | |
"new"(): Promise<DAGNode> | |
put(obj: Obj, options: PutObjectOptions, callback: Callback<CID>) | |
put(obj: Obj, options: PutObjectOptions): Promise<CID> | |
put(obj: Obj, callback: Callback<CID>) | |
put(obj: Obj): Promise<CID> | |
get( | |
multihash: Multihash, | |
options: GetObjectOptions, | |
callback: Callback<any> | |
) | |
get(multihash: Multihash, options: GetObjectOptions): Promise<any> | |
get(multihash: Multihash, callback: Callback<any>) | |
get(multihash: Multihash): Promise<any> | |
data( | |
multihash: Multihash, | |
options: GetObjectOptions, | |
callback: Callback<any> | |
) | |
data(multihash: Multihash, options: GetObjectOptions): Promise<any> | |
data(multihash: Multihash, callback: Callback<any>) | |
data(multihash: Multihash): Promise<any> | |
links( | |
multihash: Multihash, | |
options: GetObjectOptions, | |
callback: Callback<DAGLink[]> | |
) | |
links(multihash: Multihash, options: GetObjectOptions): Promise<DAGLink[]> | |
links(multihash: Multihash, callback: Callback<DAGLink[]>) | |
links(multihash: Multihash): Promise<DAGLink[]> | |
stat( | |
multihash: Multihash, | |
options: GetObjectOptions, | |
callback: Callback<ObjectStat> | |
) | |
stat(multihash: Multihash, options: GetObjectOptions): Promise<ObjectStat> | |
stat(multihash: Multihash, callback: Callback<ObjectStat>) | |
stat(multihash: Multihash): Promise<ObjectStat> | |
patch: ObjectPatchAPI | |
} | |
type DagGetResult = { | |
value: any | |
remainderPath: string | |
} | |
interface DagGetOptions { | |
localResolve?: boolean | |
} | |
type DagTreeResult = string[] | |
interface DagTreeOptions { | |
recursive?: boolean | |
} | |
export interface DagAPI { | |
put(dagNode: any, options: Object, callback: Callback<CID>) | |
put(dagNode: any, options: Object): Promise<CID> | |
get( | |
cid: string | CID, | |
path: string, | |
options: DagGetOptions, | |
callback: Callback<DagGetResult> | |
) | |
get( | |
cid: string | CID, | |
path: string, | |
options: DagGetOptions | |
): Promise<DagGetResult> | |
get(cid: string | CID, path: string, callback: Callback<DagGetResult>) | |
get(cid: string | CID, path: string): Promise<DagGetResult> | |
get(cid: string | CID, callback: Callback<DagGetResult>) | |
get(cid: string | CID): Promise<DagGetResult> | |
tree( | |
cid: string | CID, | |
path: string, | |
options: DagTreeOptions, | |
callback: Callback<DagTreeResult> | |
) | |
tree( | |
cid: string | CID, | |
path: string, | |
options: DagTreeOptions | |
): Promise<DagTreeResult> | |
tree(cid: string | CID, path: string, callback: Callback<DagTreeResult>) | |
tree(cid: string | CID, path: string): Promise<DagTreeResult> | |
tree( | |
cid: string | CID, | |
options: DagTreeOptions, | |
callback: Callback<DagTreeResult> | |
) | |
tree(cid: string | CID, options: DagTreeOptions): Promise<DagTreeResult> | |
tree(cid: string | CID, callback: Callback<DagTreeResult>) | |
tree(cid: string | CID): Promise<DagTreeResult> | |
} | |
export function createNode(options: Options): IPFS | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="./multiaddr.d.ts" /> | |
/// <reference path="./cid.d.ts" /> | |
export as namespace IPLD | |
export = IPLD | |
type Callback<T> = (error: Error, result?: T) => void | |
type Result = { remainderPath: string; value: {} } | |
interface BlockService {} | |
interface Resolver { | |
multicodec: string | |
defaultHashAlg: string | |
resolve(binaryBlob: Buffer, path: string, callback: Callback<Result>) | |
tree(binaryBlob: Buffer, callback: Callback<string[]>) | |
} | |
interface Util { | |
serialize(dagNode: {}, callback: Callback<Buffer>) | |
deserialize(binaryBlob: Buffer, callback: Callback<{}>) | |
cid( | |
binaryBlob: Buffer, | |
options: { version?: string; hashAlg?: string }, | |
callback: Callback<CID> | |
) | |
cid(binaryBlob: Buffer, callback: Callback<CID>) | |
} | |
interface Format { | |
util: Util | |
resolver: Resolver | |
} | |
type GetOptions = { localResolve?: boolean } | |
type PutOptions = { cid: CID } | { hashAlg: string; format: string } | |
declare interface IPLD { | |
bs: BlockService | |
resolvers: { [name: string]: Format } | |
put(node: {}, options: PutOptions, callback: Callback<CID>) | |
get(cid: CID, path: string, options: GetOptions, callback: Callback<Result>) | |
get(cid: CID, path: string, callback: Callback<Result>) | |
get(cid: CID, options: GetOptions, callback: Callback<Result>) | |
get(cid: CID, callback: Callback<Result>) | |
remove(cid: CID, callback: Callback<void>) | |
support: { | |
add(multicodec: string, resolver: Resolver, util: Util) | |
rm(multicodec: string) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="./multiaddr.d.ts" /> | |
import { create } from "domain" | |
export as namespace libp2p | |
export = libp2p | |
type Callback<T> = (error: Error, result?: T) => void | |
type VoidCallback = (error?: Error) => void | |
declare namespace libp2p { | |
type Peer = PeerInfo | PeerId | Multiaddr | string | |
export class Node { | |
constructor(peerInfo: PeerInfo, peerBook: PeerBook, options: Object) | |
stop(callback?: VoidCallback) | |
stop(callback?: VoidCallback) | |
dial(peer: Peer, callback: Callback<Connection>) | |
dialProtocol(peer: Peer, protocol: string, callback: Callback<Connection>) | |
hangUp(peer: Peer, callback: VoidCallback) | |
peerBook: PeerBook | |
peerRouting: PeerRoutingAPI | |
contentRouting: ContentRoutingAPI | |
pubsub: PubSubAPI | |
handle( | |
protocol: string, | |
handlerFunc: (protocol: string, conn: Connection) => void, | |
matchFunc?: ( | |
protocol: string, | |
requestedProtocol: string, | |
callback: (error: Error, match: boolean) => void | |
) => void | |
) | |
unhandle(protocol: string) | |
on(event: string, handler: (peer: PeerInfo) => void) | |
isStarted(): boolean | |
ping(peer: Peer, options: Object, callback: Callback<void>) | |
ping(peer: Peer, callback: Callback<void>) | |
} | |
interface PeerRoutingAPI { | |
findPeer(id: PeerId, callback: Callback<PeerInfo>) | |
} | |
interface ContentRoutingAPI { | |
findProviders(key: Buffer, timeout: number, callback: Callback<void>) | |
provide(key: Buffer, callback: Callback<void>) | |
} | |
export interface Message { | |
from: string | |
seqno: Buffer | |
data: Buffer | |
topicIDs: string[] | |
} | |
export interface PubSubAPI { | |
subscribe( | |
topic: string, | |
handler: (msg: Message) => void, | |
options: Object, | |
callback: VoidCallback | |
) | |
subscribe( | |
topic: string, | |
handler: (msg: Message) => void, | |
options: Object | |
): Promise<void> | |
unsubscribe(topic: string, handler: (msg: Message) => void) | |
publish(topic: string, data: Buffer, callback: VoidCallback) | |
publish(topic: string, data: Buffer): Promise<void> | |
ls(callback: Callback<string[]>) | |
ls(): Promise<string[]> | |
peers(topic: string, callback: Callback<string[]>) | |
peers(topic: string): Promise<string[]> | |
} | |
export interface Connection { | |
getObservedAddrs(callback: Callback<Multiaddr[]>) | |
getPeerInfo(callback: Callback<PeerInfo>) | |
setPeerInfo(peerInfo: PeerInfo) | |
} | |
interface PeerJSON { | |
id: string | |
pubKey: string | |
privKey: string | |
} | |
export class PeerInfo { | |
constructor(id?: PeerId) | |
create(callback: Callback<PeerInfo>) | |
create(id: PeerId | PeerJSON, callback: Callback<PeerInfo>) | |
id: PeerId | |
multiaddrs: Multiaddr[] | |
} | |
export class PeerId { | |
constructor(id: Buffer) | |
constructor(id: Buffer, privKey: any, pubKey: any) | |
create(options: Object, callback: Callback<PeerId>) | |
createFromHexString(str: string): PeerId | |
createFromBytes(buf: Buffer): PeerId | |
createFromB58String(str: string): PeerId | |
createFromPubKey(pubKey: Buffer): PeerId | |
createFromPrivKey(privKey: Buffer): PeerId | |
createFromJSON(options: PeerJSON): PeerId | |
toHexString(): string | |
toBytes(): Buffer | |
toB58String(): string | |
toJSON(): PeerJSON | |
toPrint(): PeerJSON | |
isEqual(id: PeerId | Buffer): boolean | |
} | |
export interface PeerBook { | |
put(peerInfo: PeerInfo, replace: boolean): PeerInfo | |
get(peer: Peer): PeerInfo | |
has(peer: Peer): boolean | |
getAll(): { [id: string]: PeerInfo } | |
getAllArray(): PeerInfo[] | |
getMultiaddrs(peer: Peer): Multiaddr[] | |
remove(peer: Peer) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export as namespace Multiaddr | |
export = Multiaddr | |
type Buffer = any | |
declare class Multiaddr { | |
constructor(addr: String | Buffer | Multiaddr) | |
// Static | |
static fromNodeAddress(addr: String, transport: String): Multiaddr | |
static protocols: Multiaddr.Protocol[] | |
static isMultiaddr: (addr: Multiaddr) => boolean | |
static isName: (addr: Multiaddr) => boolean | |
static resolve: ( | |
addr: Multiaddr, | |
callback: (addrs: Multiaddr[]) => void | |
) => boolean | |
// Instance | |
buffer: Buffer | |
toString: () => string | |
toOptions: () => { | |
family: string | |
host: string | |
transport: string | |
port: string | |
} | |
inspect: () => string | |
protos: () => Multiaddr.Protocol[] | |
protoCodes: () => number[] | |
protoNames: () => string[] | |
tuples: () => [number, Buffer][] | |
stringTuples: () => [number, string | number][] | |
encapsulate: (addr: Multiaddr) => Multiaddr | |
decapsulate: (addr: Multiaddr) => Multiaddr | |
getPeerId: () => string | null | |
equals: (addr: Multiaddr) => boolean | |
nodeAddress: () => { family: string; address: string; port: string } | |
isThinWaistAddress: (addr?: Multiaddr) => boolean | |
fromStupidString: (str?: string) => void | |
} | |
declare namespace Multiaddr { | |
export interface Protocol { | |
code: number | |
size: number | |
name: string | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export as namespace Multihash | |
export = Multihash | |
type Buffer = any | |
interface Multihash { | |
toHexString: (hash: Buffer) => string | |
fromHexString: (hash: string) => Buffer | |
toB58String: (hash: Buffer) => string | |
fromB58String: (hash: string) => Buffer | |
decode: ( | |
buf: Buffer | |
) => { | |
code: number | |
name: string | |
length: number | |
digest: Buffer | |
} | |
encode: (digest: Buffer, code: string | number, length?: number) => Buffer | |
coerceCode: (name: string | number) => number | |
isAppCode: (code: number) => boolean | |
isValidCode: (code: number) => boolean | |
prefix: (multihash: Buffer) => void | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These are very helpful. Thanks!