-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42dbe44
commit 818fbfc
Showing
14 changed files
with
244 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
import pdf from 'pdf-parse' | ||
import { ByteListType, ContainerType } from '@chainsafe/ssz' | ||
import { TERMS_AND_CONDITIONS_URL } from '../constants' | ||
import { strToUint8Array } from '../utils' | ||
import pdf from 'pdf-parse'; | ||
import { ByteListType, ContainerType } from '@chainsafe/ssz'; | ||
import { TERMS_AND_CONDITIONS_URL } from '../constants'; | ||
import { strToUint8Array } from '../utils'; | ||
|
||
export const hashTermsAndConditions = async (): Promise<string | null> => { | ||
try { | ||
// read the pdf | ||
const response = await fetch(TERMS_AND_CONDITIONS_URL) | ||
const pdfBuffarrayBuffer = await response.arrayBuffer() | ||
const pdfBuffer = Buffer.from(pdfBuffarrayBuffer) | ||
const data = await pdf(pdfBuffer) | ||
const response = await fetch(TERMS_AND_CONDITIONS_URL); | ||
const pdfBuffarrayBuffer = await response.arrayBuffer(); | ||
const pdfBuffer = Buffer.from(pdfBuffarrayBuffer); | ||
const data = await pdf(pdfBuffer); | ||
|
||
// ssz hash | ||
const termsType = new ContainerType({ | ||
terms_and_conditions_hash: new ByteListType(Number.MAX_SAFE_INTEGER), | ||
}) | ||
}); | ||
|
||
const termsHasVal = termsType.defaultValue() | ||
const termsHasVal = termsType.defaultValue(); | ||
|
||
termsHasVal.terms_and_conditions_hash = strToUint8Array(data?.text.replace(/[^a-zA-Z0-9]/g, '')) | ||
termsHasVal.terms_and_conditions_hash = strToUint8Array( | ||
data?.text.replace(/[^a-zA-Z0-9]/g, ''), | ||
); | ||
|
||
return ( | ||
'0x' + | ||
Buffer.from(termsType.hashTreeRoot(termsHasVal).buffer).toString('hex') | ||
) | ||
); | ||
} catch (err) { | ||
return null | ||
return null; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.