-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathindex.d.ts
214 lines (183 loc) · 4.27 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import { PrivateKey, PublicKey, KeyType } from 'libp2p-crypto'
import { CID } from 'multiformats/cid'
declare namespace PeerId {
/**
* Options for PeerId creation.
*/
interface CreateOptions {
/**
* The number of bits to use.
*/
bits?: number
/**
* The type of key to use.
*/
keyType?: KeyType
}
/**
* PeerId JSON format.
*/
interface JSONPeerId {
/**
* String representation of PeerId.
*/
id: string
/**
* Public key.
*/
pubKey?: string
/**
* Private key.
*/
privKey?: string
}
/**
* Checks if a value is an instance of PeerId.
*
* @param id - The value to check.
*/
function isPeerId (id: any): id is PeerId
/**
* Create a new PeerId.
*
* @param opts - Options.
*/
function create (opts?: PeerId.CreateOptions): Promise<PeerId>
/**
* Create PeerId from hex string.
*
* @param str - The input hex string.
*/
function createFromHexString (str: string): PeerId
/**
* Create PeerId from raw bytes.
*
* @param buf - The raw bytes.
*/
function createFromBytes (buf: Uint8Array): PeerId
/**
* Create PeerId from base58-encoded string.
*
* @param str - The base58-encoded string.
*/
function createFromB58String (str: string): PeerId
/**
* Create PeerId from CID.
*
* @param cid - The CID.
*/
function createFromCID (cid: CID): PeerId
/**
* Create PeerId from public key.
*
* @param key - Public key, as Uint8Array or base64-encoded string.
*/
function createFromPubKey (key: Uint8Array | string): Promise<PeerId>
/**
* Create PeerId from private key.
*
* @param key - Private key, as Uint8Array or base64-encoded string.
*/
function createFromPrivKey (key: Uint8Array | string): Promise<PeerId>
/**
* Create PeerId from PeerId JSON formatted object.
*
* @see {@link PeerId#toJSON}
* @param json - PeerId in JSON format.
*/
function createFromJSON (json: JSONPeerId): Promise<PeerId>
/**
* Create PeerId from Protobuf bytes.
*
* @param buf - Protobuf bytes, as Uint8Array or hex-encoded string.
*/
function createFromProtobuf (buf: Uint8Array | string): Promise<PeerId>
/**
* Parse a PeerId from a string.
*
* @param str - encoded public key string.
*/
function parse (str: string): PeerId
}
/**
* PeerId is an object representation of a peer identifier.
*/
declare class PeerId {
constructor (id: Uint8Array, privKey?: PrivateKey, pubKey?: PublicKey);
/**
* Raw id.
*/
readonly id: Uint8Array
/**
* Private key.
*/
privKey: PrivateKey
/**
* Public key.
*/
pubKey: PublicKey
/**
* Return the protobuf version of the public key, matching go ipfs formatting.
*/
marshalPubKey (): Uint8Array;
/**
* Return the protobuf version of the private key, matching go ipfs formatting.
*/
marshalPrivKey (): Uint8Array;
/**
* Return the protobuf version of the peer-id.
*
* @param excludePriv - Whether to exclude the private key information from the output.
*/
marshal (excludePriv?: boolean): Uint8Array;
/**
* String representation.
*/
toPrint (): string;
/**
* Return the jsonified version of the key.
* Matches the formatting of go-ipfs for its config file.
*
* @see {@link PeerId.createFromJSON}
*/
toJSON (): PeerId.JSONPeerId;
/**
* Encode to hex.
*/
toHexString (): string;
/**
* Return raw id bytes.
*/
toBytes (): Uint8Array;
/**
* Encode to base58 string.
*/
toB58String (): string;
/**
* Return self-describing string representation.
* Uses default format from RFC 0001: https://github.com/libp2p/specs/pull/209
*/
toString (): string;
/**
* Checks the equality of `this` peer against a given PeerId.
*
* @param id - The other PeerId.
*/
equals (id: PeerId | Uint8Array): boolean;
/**
* Checks the equality of `this` peer against a given PeerId.
*
* @deprecated Use {.equals}
* @param id - The other PeerId.
*/
isEqual (id: PeerId | Uint8Array): boolean;
/**
* Check if this PeerId instance is valid (privKey -> pubKey -> Id)
*/
isValid (): boolean;
/**
* Check if the PeerId has an inline public key.
*/
hasInlinePublicKey (): boolean;
}
export = PeerId