In this function,
|
export async function resolveDNSFromZKEmailArchive(name: string, type: string) { |
|
if (type !== 'TXT') { |
|
throw new Error(`ZK Email Archive only supports TXT records - got ${type}`); |
|
} |
|
|
|
// Get domain from full dns record name - $selector._domainkey.$domain.com |
|
const domain = name.split('.').slice(2).join('.'); |
|
const selector = name.split('.')[0]; |
|
|
|
const queryUrl = new URL(ZKEMAIL_DNS_ARCHIVER_API); |
|
queryUrl.searchParams.set('domain', domain); |
|
|
|
const resp = await fetch(queryUrl); |
|
const data = await resp.json(); |
|
|
|
const dkimRecord = data.find((record: any) => record.selector === selector); |
|
|
|
if (!dkimRecord) { |
|
throw new CustomError( |
|
`DKIM record not found for domain ${domain} and selector ${selector} in ZK Email Archive.`, |
|
'ENODATA', |
|
); |
|
} |
|
|
|
return [dkimRecord.value]; |
|
} |
We are currently using the function below, which fetches the DKIM key using the domain and checks only the first selector that matches the domain-selector.
However, in our case, a single DSP can be associated with multiple DKIM keys. So instead of validating the email using just the first key, we need to verify it against all keys that share the same DSP. and we have to make sure verification is happening with all the keys, and if it don't find any suitable key, it should return the bad signature error
|
const dkimRecord = data.find((record: any) => record.selector === selector); |
In this function,
zk-email-verify/packages/helpers/src/dkim/dns-archive.ts
Lines 5 to 30 in 33ddc96
We are currently using the function below, which fetches the DKIM key using the domain and checks only the first selector that matches the domain-selector.
However, in our case, a single DSP can be associated with multiple DKIM keys. So instead of validating the email using just the first key, we need to verify it against all keys that share the same DSP. and we have to make sure verification is happening with all the keys, and if it don't find any suitable key, it should return the bad signature error
zk-email-verify/packages/helpers/src/dkim/dns-archive.ts
Line 20 in 33ddc96