-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: michalrozekariane <[email protected]> Signed-off-by: kacper-koza-arianelabs <[email protected]> Co-authored-by: kacper-koza-arianelabs <[email protected]>
- Loading branch information
1 parent
d34d09f
commit f9ee518
Showing
19 changed files
with
1,072 additions
and
607 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*- | ||
* | ||
* Hedera NFT SDK | ||
* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import axios from 'axios'; | ||
import { decodeMetadataURL } from '../helpers/decode-metadata-url'; | ||
import { CollectionMetadataSchema } from '../utils/validation-schemas/hip766-collection-metadata-schema'; | ||
import { validateObjectWithSchema, validationMetadataErrorOptions } from '../helpers/validate-object-with-schema'; | ||
import { ValidationError } from '../utils/validation-error'; | ||
import { errorToMessage } from '../helpers/error-to-message'; | ||
import { dictionary } from '../utils/constants/dictionary'; | ||
|
||
export const validateCollectionMetadata = async ( | ||
metadataURL: string, | ||
ipfsGateway?: string | ||
): Promise<{ errors: string[]; isValid: boolean }> => { | ||
const errors: string[] = []; | ||
|
||
if (metadataURL.length === 0) { | ||
errors.push(dictionary.validation.uriIsRequired); | ||
return { errors, isValid: false }; | ||
} | ||
|
||
const decodedUri = decodeMetadataURL(metadataURL, ipfsGateway); | ||
|
||
try { | ||
const response = await axios.get(decodedUri, { responseType: 'json' }); | ||
const metadata = response.data; | ||
|
||
try { | ||
validateObjectWithSchema(CollectionMetadataSchema, metadata, validationMetadataErrorOptions); | ||
} catch (error) { | ||
if (error instanceof ValidationError) { | ||
errors.push(...error.errors); | ||
} else { | ||
errors.push(errorToMessage(error)); | ||
} | ||
} | ||
} catch (error: unknown) { | ||
if (error instanceof Error) { | ||
errors.push(`${dictionary.errors.failedToFetchMetadata}: ${error.message}`); | ||
} else { | ||
errors.push(dictionary.errors.unhandledError); | ||
} | ||
} | ||
|
||
return { errors, isValid: errors.length === 0 }; | ||
}; |
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
19 changes: 19 additions & 0 deletions
19
src/test/e2e/calculate-rarity-from-on-chain-data-e2e.test.ts
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
19 changes: 19 additions & 0 deletions
19
...test/e2e/hip412-validation/create-and-validate-shared-nft-collection-metadata-e2e.test.ts
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
19 changes: 19 additions & 0 deletions
19
src/test/e2e/hip412-validation/validate-single-on-chain-nft-metadata-e2e.test.ts
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.