Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getClaims(
kit: ContractKit,
address: string,
data: IdentityMetadataWrapper
): Promise {
if (address.substr(0, 2) === '0x') {
address = address.substr(2)
}
const res = [address]
const accounts = await kit.contracts.getAccounts()
for (const claim of data.claims) {
switch (claim.type) {
case ClaimTypes.KEYBASE:
break
case ClaimTypes.ACCOUNT:
try {
const status = await verifyAccountClaim(claim, '0x' + address, accounts.getMetadataURL)
if (status) console.error('Cannot verify claim:', status)
else {
console.log('Claim success', address, claim.address)
res.push(claim.address)
}
} catch (err) {
console.error('Cannot fetch metadata', err)
}
default:
break
}
}
const verifiable = VERIFIABLE_CLAIM_TYPES.includes(claim.type)
const validatable = VALIDATABLE_CLAIM_TYPES.includes(claim.type)
const status = verifiable
? await verifyClaim(claim, metadata.data.meta.address, metadataURLGetter)
: validatable
? await validateClaim(claim, metadata.data.meta.address, kit)
: 'N/A'
let extra = ''
switch (claim.type) {
case ClaimTypes.ATTESTATION_SERVICE_URL:
extra = `URL: ${claim.url}`
break
case ClaimTypes.DOMAIN:
extra = `Domain: ${claim.domain}`
break
case ClaimTypes.KEYBASE:
extra = `Username: ${claim.username}`
break
case ClaimTypes.NAME:
extra = `Name: "${claim.name}"`
break
default:
extra = JSON.stringify(claim)
break
}
return {
type: claim.type,
extra,
status: verifiable
? status
? `Could not verify: ${status}`
: 'Verified!'