# All files / src/profiles profileProofs.ts

88.24% Statements 15/17
81.25% Branches 13/16
100% Functions 2/2
88.24% Lines 15/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    651x

    1x

    2x

    2x
    2x

    2x
    2x

    2x

    8x

    2x

    6x

    2x

    4x

    4x

    2x

     import { profileServices } from './services'
    import { CheerioModuleType } from './services/service'

    export interface AccountProofInfo {
      service: string;
      identifier: string;
      proof_url: string;
      proofType?: string;
      valid?: boolean;
    }

    /**
     * Validates the social proofs in a user's profile. Currently supports validation of
     * Facebook, Twitter, GitHub, Instagram, LinkedIn and HackerNews accounts.
     *
     * @param {Object} profile The JSON of the profile to be validated
     * @param {string} ownerAddress The owner bitcoin address to be validated
     * @param {string} [name=null] The Blockstack name to be validated
     * @returns {Promise} that resolves to an array of validated proof objects
     */
    export function validateProofs(profile: any,
                                   ownerAddress: string,
                                   cheerio: CheerioModuleType,
                                   name: string = null): Promise<AccountProofInfo[]> {
      Iif (!profile) {
        throw new Error('Profile must not be null')
      }

      let accounts: any[] = []
      const proofsToValidate: Promise<AccountProofInfo>[] = []

      Eif (profile.hasOwnProperty('account')) {
        accounts = profile.account
      } else {
        return Promise.resolve([])
      }

      accounts.forEach((account) => {
        // skip if proof service is not supported
        if (account.hasOwnProperty('service')
            && !profileServices.hasOwnProperty(account.service)) {
          return
        }

        if (!(account.hasOwnProperty('proofType')
            && account.proofType === 'http'
            && account.hasOwnProperty('proofUrl'))) {
          return
        }

        const proof: AccountProofInfo = {
          proofType: account.proofType,
          service: account.service,
          proof_url: account.proof_url || account.proofUrl,
          identifier: account.identifier,
          valid: false
        }

        proofsToValidate.push(profileServices[account.service]
          .validateProof(proof, ownerAddress, cheerio, name))
      })

      return Promise.all(proofsToValidate)
    }