| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import Config, { RecordHash, RecordMate } from './config'
- export type RecordProps = {
- config: Config
- }
- class Record {
- private config: Config
- constructor(options: RecordProps) {
- this.config = options.config
- }
- public getHosts() {
- return this.config.getRecord()?.hosts
- }
- public getHash() {
- return this.config.getRecord()?.hash
- }
- public contains(hosts: string[]) {
- const oldHosts = this.getHosts()
- if (!oldHosts) {
- return false
- }
- // require hosts is subset of oldHosts
- for (const host of hosts) {
- if (!oldHosts.includes(host)) {
- return false
- }
- }
- return true
- }
- // whether the files has been tampered with
- public tamper(hash: RecordHash) {
- const oldHash = this.getHash()
- if (!oldHash) {
- return false
- }
- if (oldHash.key === hash.key && oldHash.cert === hash.cert) {
- return false
- }
- return true
- }
- public async update(record: RecordMate) {
- await this.config.merge({ record })
- }
- }
- export default Record
|