role.d.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { JSONObject, JSONValue } from './utils';
  2. export declare const TOP_LEVEL_ROLE_NAMES: string[];
  3. export interface RoleOptions {
  4. keyIDs: string[];
  5. threshold: number;
  6. unrecognizedFields?: Record<string, JSONValue>;
  7. }
  8. /**
  9. * Container that defines which keys are required to sign roles metadata.
  10. *
  11. * Role defines how many keys are required to successfully sign the roles
  12. * metadata, and which keys are accepted.
  13. */
  14. export declare class Role {
  15. readonly keyIDs: string[];
  16. readonly threshold: number;
  17. readonly unrecognizedFields?: Record<string, JSONValue>;
  18. constructor(options: RoleOptions);
  19. equals(other: Role): boolean;
  20. toJSON(): JSONObject;
  21. static fromJSON(data: JSONObject): Role;
  22. }
  23. interface DelegatedRoleOptions extends RoleOptions {
  24. name: string;
  25. terminating: boolean;
  26. paths?: string[];
  27. pathHashPrefixes?: string[];
  28. }
  29. /**
  30. * A container with information about a delegated role.
  31. *
  32. * A delegation can happen in two ways:
  33. * - ``paths`` is set: delegates targets matching any path pattern in ``paths``
  34. * - ``pathHashPrefixes`` is set: delegates targets whose target path hash
  35. * starts with any of the prefixes in ``pathHashPrefixes``
  36. *
  37. * ``paths`` and ``pathHashPrefixes`` are mutually exclusive: both cannot be
  38. * set, at least one of them must be set.
  39. */
  40. export declare class DelegatedRole extends Role {
  41. readonly name: string;
  42. readonly terminating: boolean;
  43. readonly paths?: string[];
  44. readonly pathHashPrefixes?: string[];
  45. constructor(opts: DelegatedRoleOptions);
  46. equals(other: DelegatedRole): boolean;
  47. isDelegatedPath(targetFilepath: string): boolean;
  48. toJSON(): JSONObject;
  49. static fromJSON(data: JSONObject): DelegatedRole;
  50. }
  51. interface SuccinctRolesOption extends RoleOptions {
  52. bitLength: number;
  53. namePrefix: string;
  54. }
  55. /**
  56. * Succinctly defines a hash bin delegation graph.
  57. *
  58. * A ``SuccinctRoles`` object describes a delegation graph that covers all
  59. * targets, distributing them uniformly over the delegated roles (i.e. bins)
  60. * in the graph.
  61. *
  62. * The total number of bins is 2 to the power of the passed ``bit_length``.
  63. *
  64. * Bin names are the concatenation of the passed ``name_prefix`` and a
  65. * zero-padded hex representation of the bin index separated by a hyphen.
  66. *
  67. * The passed ``keyids`` and ``threshold`` is used for each bin, and each bin
  68. * is 'terminating'.
  69. *
  70. * For details: https://github.com/theupdateframework/taps/blob/master/tap15.md
  71. */
  72. export declare class SuccinctRoles extends Role {
  73. readonly bitLength: number;
  74. readonly namePrefix: string;
  75. readonly numberOfBins: number;
  76. readonly suffixLen: number;
  77. constructor(opts: SuccinctRolesOption);
  78. equals(other: SuccinctRoles): boolean;
  79. /***
  80. * Calculates the name of the delegated role responsible for 'target_filepath'.
  81. *
  82. * The target at path ''target_filepath' is assigned to a bin by casting
  83. * the left-most 'bit_length' of bits of the file path hash digest to
  84. * int, using it as bin index between 0 and '2**bit_length - 1'.
  85. *
  86. * Args:
  87. * target_filepath: URL path to a target file, relative to a base
  88. * targets URL.
  89. */
  90. getRoleForTarget(targetFilepath: string): string;
  91. getRoles(): Generator<string>;
  92. /***
  93. * Determines whether the given ``role_name`` is in one of
  94. * the delegated roles that ``SuccinctRoles`` represents.
  95. *
  96. * Args:
  97. * role_name: The name of the role to check against.
  98. */
  99. isDelegatedRole(roleName: string): boolean;
  100. toJSON(): JSONObject;
  101. static fromJSON(data: JSONObject): SuccinctRoles;
  102. }
  103. export {};