ipv6.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. import * as common from './common';
  2. import { Address4 } from './ipv4';
  3. import { BigInteger } from 'jsbn';
  4. interface SixToFourProperties {
  5. prefix: string;
  6. gateway: string;
  7. }
  8. interface TeredoProperties {
  9. prefix: string;
  10. server4: string;
  11. client4: string;
  12. flags: string;
  13. coneNat: boolean;
  14. microsoft: {
  15. reserved: boolean;
  16. universalLocal: boolean;
  17. groupIndividual: boolean;
  18. nonce: string;
  19. };
  20. udpPort: string;
  21. }
  22. /**
  23. * Represents an IPv6 address
  24. * @class Address6
  25. * @param {string} address - An IPv6 address string
  26. * @param {number} [groups=8] - How many octets to parse
  27. * @example
  28. * var address = new Address6('2001::/32');
  29. */
  30. export declare class Address6 {
  31. address4?: Address4;
  32. address: string;
  33. addressMinusSuffix: string;
  34. elidedGroups?: number;
  35. elisionBegin?: number;
  36. elisionEnd?: number;
  37. groups: number;
  38. parsedAddress4?: string;
  39. parsedAddress: string[];
  40. parsedSubnet: string;
  41. subnet: string;
  42. subnetMask: number;
  43. v4: boolean;
  44. zone: string;
  45. constructor(address: string, optionalGroups?: number);
  46. static isValid(address: string): boolean;
  47. /**
  48. * Convert a BigInteger to a v6 address object
  49. * @memberof Address6
  50. * @static
  51. * @param {BigInteger} bigInteger - a BigInteger to convert
  52. * @returns {Address6}
  53. * @example
  54. * var bigInteger = new BigInteger('1000000000000');
  55. * var address = Address6.fromBigInteger(bigInteger);
  56. * address.correctForm(); // '::e8:d4a5:1000'
  57. */
  58. static fromBigInteger(bigInteger: BigInteger): Address6;
  59. /**
  60. * Convert a URL (with optional port number) to an address object
  61. * @memberof Address6
  62. * @static
  63. * @param {string} url - a URL with optional port number
  64. * @example
  65. * var addressAndPort = Address6.fromURL('http://[ffff::]:8080/foo/');
  66. * addressAndPort.address.correctForm(); // 'ffff::'
  67. * addressAndPort.port; // 8080
  68. */
  69. static fromURL(url: string): {
  70. error: string;
  71. address: null;
  72. port: null;
  73. } | {
  74. address: Address6;
  75. port: number | null;
  76. error?: undefined;
  77. };
  78. /**
  79. * Create an IPv6-mapped address given an IPv4 address
  80. * @memberof Address6
  81. * @static
  82. * @param {string} address - An IPv4 address string
  83. * @returns {Address6}
  84. * @example
  85. * var address = Address6.fromAddress4('192.168.0.1');
  86. * address.correctForm(); // '::ffff:c0a8:1'
  87. * address.to4in6(); // '::ffff:192.168.0.1'
  88. */
  89. static fromAddress4(address: string): Address6;
  90. /**
  91. * Return an address from ip6.arpa form
  92. * @memberof Address6
  93. * @static
  94. * @param {string} arpaFormAddress - an 'ip6.arpa' form address
  95. * @returns {Adress6}
  96. * @example
  97. * var address = Address6.fromArpa(e.f.f.f.3.c.2.6.f.f.f.e.6.6.8.e.1.0.6.7.9.4.e.c.0.0.0.0.1.0.0.2.ip6.arpa.)
  98. * address.correctForm(); // '2001:0:ce49:7601:e866:efff:62c3:fffe'
  99. */
  100. static fromArpa(arpaFormAddress: string): Address6;
  101. /**
  102. * Return the Microsoft UNC transcription of the address
  103. * @memberof Address6
  104. * @instance
  105. * @returns {String} the Microsoft UNC transcription of the address
  106. */
  107. microsoftTranscription(): string;
  108. /**
  109. * Return the first n bits of the address, defaulting to the subnet mask
  110. * @memberof Address6
  111. * @instance
  112. * @param {number} [mask=subnet] - the number of bits to mask
  113. * @returns {String} the first n bits of the address as a string
  114. */
  115. mask(mask?: number): string;
  116. /**
  117. * Return the number of possible subnets of a given size in the address
  118. * @memberof Address6
  119. * @instance
  120. * @param {number} [size=128] - the subnet size
  121. * @returns {String}
  122. */
  123. possibleSubnets(subnetSize?: number): string;
  124. /**
  125. * Helper function getting start address.
  126. * @memberof Address6
  127. * @instance
  128. * @returns {BigInteger}
  129. */
  130. _startAddress(): BigInteger;
  131. /**
  132. * The first address in the range given by this address' subnet
  133. * Often referred to as the Network Address.
  134. * @memberof Address6
  135. * @instance
  136. * @returns {Address6}
  137. */
  138. startAddress(): Address6;
  139. /**
  140. * The first host address in the range given by this address's subnet ie
  141. * the first address after the Network Address
  142. * @memberof Address6
  143. * @instance
  144. * @returns {Address6}
  145. */
  146. startAddressExclusive(): Address6;
  147. /**
  148. * Helper function getting end address.
  149. * @memberof Address6
  150. * @instance
  151. * @returns {BigInteger}
  152. */
  153. _endAddress(): BigInteger;
  154. /**
  155. * The last address in the range given by this address' subnet
  156. * Often referred to as the Broadcast
  157. * @memberof Address6
  158. * @instance
  159. * @returns {Address6}
  160. */
  161. endAddress(): Address6;
  162. /**
  163. * The last host address in the range given by this address's subnet ie
  164. * the last address prior to the Broadcast Address
  165. * @memberof Address6
  166. * @instance
  167. * @returns {Address6}
  168. */
  169. endAddressExclusive(): Address6;
  170. /**
  171. * Return the scope of the address
  172. * @memberof Address6
  173. * @instance
  174. * @returns {String}
  175. */
  176. getScope(): string;
  177. /**
  178. * Return the type of the address
  179. * @memberof Address6
  180. * @instance
  181. * @returns {String}
  182. */
  183. getType(): string;
  184. /**
  185. * Return the bits in the given range as a BigInteger
  186. * @memberof Address6
  187. * @instance
  188. * @returns {BigInteger}
  189. */
  190. getBits(start: number, end: number): BigInteger;
  191. /**
  192. * Return the bits in the given range as a base-2 string
  193. * @memberof Address6
  194. * @instance
  195. * @returns {String}
  196. */
  197. getBitsBase2(start: number, end: number): string;
  198. /**
  199. * Return the bits in the given range as a base-16 string
  200. * @memberof Address6
  201. * @instance
  202. * @returns {String}
  203. */
  204. getBitsBase16(start: number, end: number): string;
  205. /**
  206. * Return the bits that are set past the subnet mask length
  207. * @memberof Address6
  208. * @instance
  209. * @returns {String}
  210. */
  211. getBitsPastSubnet(): string;
  212. /**
  213. * Return the reversed ip6.arpa form of the address
  214. * @memberof Address6
  215. * @param {Object} options
  216. * @param {boolean} options.omitSuffix - omit the "ip6.arpa" suffix
  217. * @instance
  218. * @returns {String}
  219. */
  220. reverseForm(options?: common.ReverseFormOptions): string;
  221. /**
  222. * Return the correct form of the address
  223. * @memberof Address6
  224. * @instance
  225. * @returns {String}
  226. */
  227. correctForm(): string;
  228. /**
  229. * Return a zero-padded base-2 string representation of the address
  230. * @memberof Address6
  231. * @instance
  232. * @returns {String}
  233. * @example
  234. * var address = new Address6('2001:4860:4001:803::1011');
  235. * address.binaryZeroPad();
  236. * // '0010000000000001010010000110000001000000000000010000100000000011
  237. * // 0000000000000000000000000000000000000000000000000001000000010001'
  238. */
  239. binaryZeroPad(): string;
  240. parse4in6(address: string): string;
  241. parse(address: string): string[];
  242. /**
  243. * Return the canonical form of the address
  244. * @memberof Address6
  245. * @instance
  246. * @returns {String}
  247. */
  248. canonicalForm(): string;
  249. /**
  250. * Return the decimal form of the address
  251. * @memberof Address6
  252. * @instance
  253. * @returns {String}
  254. */
  255. decimal(): string;
  256. /**
  257. * Return the address as a BigInteger
  258. * @memberof Address6
  259. * @instance
  260. * @returns {BigInteger}
  261. */
  262. bigInteger(): BigInteger;
  263. /**
  264. * Return the last two groups of this address as an IPv4 address string
  265. * @memberof Address6
  266. * @instance
  267. * @returns {Address4}
  268. * @example
  269. * var address = new Address6('2001:4860:4001::1825:bf11');
  270. * address.to4().correctForm(); // '24.37.191.17'
  271. */
  272. to4(): Address4;
  273. /**
  274. * Return the v4-in-v6 form of the address
  275. * @memberof Address6
  276. * @instance
  277. * @returns {String}
  278. */
  279. to4in6(): string;
  280. /**
  281. * Return an object containing the Teredo properties of the address
  282. * @memberof Address6
  283. * @instance
  284. * @returns {Object}
  285. */
  286. inspectTeredo(): TeredoProperties;
  287. /**
  288. * Return an object containing the 6to4 properties of the address
  289. * @memberof Address6
  290. * @instance
  291. * @returns {Object}
  292. */
  293. inspect6to4(): SixToFourProperties;
  294. /**
  295. * Return a v6 6to4 address from a v6 v4inv6 address
  296. * @memberof Address6
  297. * @instance
  298. * @returns {Address6}
  299. */
  300. to6to4(): Address6 | null;
  301. /**
  302. * Return a byte array
  303. * @memberof Address6
  304. * @instance
  305. * @returns {Array}
  306. */
  307. toByteArray(): number[];
  308. /**
  309. * Return an unsigned byte array
  310. * @memberof Address6
  311. * @instance
  312. * @returns {Array}
  313. */
  314. toUnsignedByteArray(): number[];
  315. /**
  316. * Convert a byte array to an Address6 object
  317. * @memberof Address6
  318. * @static
  319. * @returns {Address6}
  320. */
  321. static fromByteArray(bytes: Array<any>): Address6;
  322. /**
  323. * Convert an unsigned byte array to an Address6 object
  324. * @memberof Address6
  325. * @static
  326. * @returns {Address6}
  327. */
  328. static fromUnsignedByteArray(bytes: Array<any>): Address6;
  329. /**
  330. * Returns true if the given address is in the subnet of the current address
  331. * @memberof Address6
  332. * @instance
  333. * @returns {boolean}
  334. */
  335. isInSubnet: typeof common.isInSubnet;
  336. /**
  337. * Returns true if the address is correct, false otherwise
  338. * @memberof Address6
  339. * @instance
  340. * @returns {boolean}
  341. */
  342. isCorrect: (this: Address4 | Address6) => boolean;
  343. /**
  344. * Returns true if the address is in the canonical form, false otherwise
  345. * @memberof Address6
  346. * @instance
  347. * @returns {boolean}
  348. */
  349. isCanonical(): boolean;
  350. /**
  351. * Returns true if the address is a link local address, false otherwise
  352. * @memberof Address6
  353. * @instance
  354. * @returns {boolean}
  355. */
  356. isLinkLocal(): boolean;
  357. /**
  358. * Returns true if the address is a multicast address, false otherwise
  359. * @memberof Address6
  360. * @instance
  361. * @returns {boolean}
  362. */
  363. isMulticast(): boolean;
  364. /**
  365. * Returns true if the address is a v4-in-v6 address, false otherwise
  366. * @memberof Address6
  367. * @instance
  368. * @returns {boolean}
  369. */
  370. is4(): boolean;
  371. /**
  372. * Returns true if the address is a Teredo address, false otherwise
  373. * @memberof Address6
  374. * @instance
  375. * @returns {boolean}
  376. */
  377. isTeredo(): boolean;
  378. /**
  379. * Returns true if the address is a 6to4 address, false otherwise
  380. * @memberof Address6
  381. * @instance
  382. * @returns {boolean}
  383. */
  384. is6to4(): boolean;
  385. /**
  386. * Returns true if the address is a loopback address, false otherwise
  387. * @memberof Address6
  388. * @instance
  389. * @returns {boolean}
  390. */
  391. isLoopback(): boolean;
  392. /**
  393. * @returns {String} the address in link form with a default port of 80
  394. */
  395. href(optionalPort?: number | string): string;
  396. /**
  397. * @returns {String} a link suitable for conveying the address via a URL hash
  398. */
  399. link(options?: {
  400. className?: string;
  401. prefix?: string;
  402. v4?: boolean;
  403. }): string;
  404. /**
  405. * Groups an address
  406. * @returns {String}
  407. */
  408. group(): string;
  409. /**
  410. * Generate a regular expression string that can be used to find or validate
  411. * all variations of this address
  412. * @memberof Address6
  413. * @instance
  414. * @param {boolean} substringSearch
  415. * @returns {string}
  416. */
  417. regularExpressionString(this: Address6, substringSearch?: boolean): string;
  418. /**
  419. * Generate a regular expression that can be used to find or validate all
  420. * variations of this address.
  421. * @memberof Address6
  422. * @instance
  423. * @param {boolean} substringSearch
  424. * @returns {RegExp}
  425. */
  426. regularExpression(this: Address6, substringSearch?: boolean): RegExp;
  427. }
  428. export {};
  429. //# sourceMappingURL=ipv6.d.ts.map