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