diff --git a/src/base/token_uris.cairo b/src/base/token_uris.cairo index f3ba9d6..8fe6de3 100644 --- a/src/base/token_uris.cairo +++ b/src/base/token_uris.cairo @@ -1,3 +1,4 @@ mod follow_token_uri; mod handle_token_uri; mod profile_token_uri; +mod traits; diff --git a/src/base/token_uris/follow_token_uri.cairo b/src/base/token_uris/follow_token_uri.cairo index c493b2a..6150145 100644 --- a/src/base/token_uris/follow_token_uri.cairo +++ b/src/base/token_uris/follow_token_uri.cairo @@ -4,10 +4,65 @@ pub mod FollowTokenUri { use starknet::ContractAddress; use alexandria_bytes::{Bytes, BytesTrait}; use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; + use karst::base::utils::base64_extended::{convert_into_byteArray, get_base64_encode}; + use karst::base::token_uris::traits::follow::follow::get_svg_follow; pub fn get_token_uri( follow_token_id: u256, followed_profile_address: ContractAddress, follow_timestamp: u64 ) -> ByteArray { - "TODO" + let baseuri = 'data:image/svg+xml;base64,'; + /// TODO what are feaature include in the svg + let mut svg_byte_array: ByteArray = get_svg_follow(follow_token_id); + let mut svg_encoded: ByteArray = get_base64_encode(svg_byte_array); + let mut attribute_byte_array: ByteArray = get_attributes( + follow_token_id, ref svg_encoded, followed_profile_address, follow_timestamp + ); + let mut token_uri: ByteArray = baseuri.try_into().unwrap(); + token_uri.append(@attribute_byte_array); + token_uri + } + + fn get_attributes( + token_id: u256, + ref svg_encoded_byteArray: ByteArray, + followed_profile_address: ContractAddress, + follow_timestamp: u64 + ) -> ByteArray { + let token_id_felt: felt252 = token_id.try_into().unwrap(); + let follow_profile_address_felt: felt252 = followed_profile_address.try_into().unwrap(); + let follow_prfile_address_byte: ByteArray = follow_profile_address_felt.try_into().unwrap(); + let follow_prfile_address_byte_len: felt252 = follow_prfile_address_byte + .len() + .try_into() + .unwrap(); + let mut attributespre = ArrayTrait::::new(); + let mut attributespost = ArrayTrait::::new(); + attributespre.append('{"name":"Follower #'); + attributespre.append(token_id_felt); + attributespre.append('","description":"Lens '); + attributespre.append('Protocol - Follower @'); + attributespre.append(token_id_felt); + attributespre.append(' of Profile #'); + attributespre.append(follow_profile_address_felt); + attributespre.append('","image":"data:image'); + attributespre.append('/svg+xml;base64,'); + //post base64 follow svg + attributespost.append('","attributes":[{"display'); + attributespost.append('_type":"number","trait_type'); + attributespost.append('":"ID","value":"'); + attributespost.append(token_id_felt); + attributespost.append('"},{"trait_type":"DIGITS"'); + attributespost.append(',"value":"'); + attributespost.append(follow_prfile_address_byte_len); + attributespost.append('"},{"display_type":"date'); + attributespost.append('","trait_type":"MINTED AT"'); + attributespost.append(',"value":"'); + attributespost.append(follow_timestamp.try_into().unwrap()); + attributespost.append('"}]}'); + let mut attributespre_bytearray = convert_into_byteArray(ref attributespre); + let mut attributespost_bytearray = convert_into_byteArray(ref attributespost); + attributespre_bytearray.append(@svg_encoded_byteArray); + attributespre_bytearray.append(@attributespost_bytearray); + get_base64_encode(attributespre_bytearray) } } diff --git a/src/base/token_uris/handle_token_uri.cairo b/src/base/token_uris/handle_token_uri.cairo index 56fd220..4b3266a 100644 --- a/src/base/token_uris/handle_token_uri.cairo +++ b/src/base/token_uris/handle_token_uri.cairo @@ -1,10 +1,56 @@ // TODO: https://github.com/lens-protocol/core/blob/master/contracts/misc/token-uris/HandleTokenURI.sol pub mod HandleTokenUri { + use core::array::ArrayTrait; use alexandria_bytes::{Bytes, BytesTrait}; use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; + use karst::base::utils::base64_extended::{convert_into_byteArray, get_base64_encode}; + use karst::base::token_uris::traits::handle::handle::get_svg_handle; pub fn get_token_uri(token_id: u256, local_name: felt252, namespace: felt252) -> ByteArray { - "TODO" + let baseuri = 'data:image/svg+xml;base64,'; + /// TODO what are feaature include in the svg + let mut svg_byte_array: ByteArray = get_svg_handle(token_id, local_name, namespace); + let mut svg_encoded: ByteArray = get_base64_encode(svg_byte_array); + let mut attribute_byte_array: ByteArray = get_attributes( + token_id, ref svg_encoded, local_name, namespace + ); + let mut token_uri: ByteArray = baseuri.try_into().unwrap(); + token_uri.append(@attribute_byte_array); + token_uri + } + + fn get_attributes( + token_id: u256, + ref svg_encoded_byteArray: ByteArray, + local_name: felt252, + namespace: felt252 + ) -> ByteArray { + let mut attributespre = ArrayTrait::::new(); + let mut attributespost = ArrayTrait::::new(); + attributespre.append('{"name":"@'); + attributespre.append(local_name); + attributespre.append('","description":"Lens '); + attributespre.append('Protocol - Handle @'); + attributespre.append(local_name); + attributespre.append('","image":"data:image'); + attributespre.append('/svg+xml;base64,'); + attributespost.append('","attributes":[{"display'); + attributespost.append('_type":"number","trait_type'); + attributespost.append('":"ID","value":"'); + attributespost.append(token_id.try_into().unwrap()); + attributespost.append('"},{"trait_type":"NAMES'); + attributespost.append('PACE","value":"'); + attributespost.append(namespace); + attributespost.append('"},{"trait_type":"'); + attributespost.append('LENGTH","value":"'); + attributespost.append('token_id_byte_len'); + attributespost.append('"}]}'); + let mut attributespre_bytearray = convert_into_byteArray(ref attributespre); + let mut attributespost_bytearray = convert_into_byteArray(ref attributespost); + attributespre_bytearray.append(@svg_encoded_byteArray); + attributespre_bytearray.append(@attributespost_bytearray); + get_base64_encode(attributespre_bytearray) } } + diff --git a/src/base/token_uris/profile_token_uri.cairo b/src/base/token_uris/profile_token_uri.cairo index e469882..a337351 100644 --- a/src/base/token_uris/profile_token_uri.cairo +++ b/src/base/token_uris/profile_token_uri.cairo @@ -4,9 +4,9 @@ pub mod ProfileTokenUri { use core::array::ArrayTrait; use alexandria_bytes::{Bytes, BytesTrait}; use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; - use alexandria_encoding::base64::{Base64UrlEncoder}; + use karst::base::utils::base64_extended::{get_base64_encode, convert_into_byteArray}; + use karst::base::token_uris::traits::profile::ProfileSvg::gen_profile_svg; - // get svg according to the token id and mint timestamp fn get_svg(token_id: u256, mint_timestamp: u64) -> Array { let mut svg = ArrayTrait::::new(); svg.append(') -> ByteArray { - let mut res: ByteArray = Default::default(); - // converting felt252 array to byte array - while (!svg.is_empty()) { - let each_felt: felt252 = svg.pop_front().unwrap(); - let word: ByteArray = each_felt.try_into().unwrap(); - res.append(@word); - }; - res - } - - fn get_base64_encode(res: ByteArray) -> ByteArray { - let mut res_arr_u8 = ArrayTrait::::new(); - let mut i = 0; - while i < res - .len() { - let mut res_data = res.at(i); - res_arr_u8.append(res_data.unwrap()); - i += 1; - }; - // encoding the array of u8 to base64url - let mut encoded_val = Base64UrlEncoder::encode(res_arr_u8); - // converting array of u8 to byte array - let mut res_final: ByteArray = Default::default(); - let mut j = 0; - while j < encoded_val - .len() { - let encoded_val_data = encoded_val.at(j); - res_final.append_byte(*encoded_val_data); - j += 1; - }; - res_final - } pub fn get_token_uri(token_id: u256, mint_timestamp: u64) -> ByteArray { let baseuri = 'data:image/svg+xml;base64,'; diff --git a/src/base/token_uris/traits.cairo b/src/base/token_uris/traits.cairo new file mode 100644 index 0000000..3ae4bce --- /dev/null +++ b/src/base/token_uris/traits.cairo @@ -0,0 +1,9 @@ +mod head; +mod glass; +mod color; +mod beard; +mod background; +mod cloth; +mod profile; +mod handle; +mod follow; diff --git a/src/base/token_uris/traits/background.cairo b/src/base/token_uris/traits/background.cairo new file mode 100644 index 0000000..0c174f7 --- /dev/null +++ b/src/base/token_uris/traits/background.cairo @@ -0,0 +1,42 @@ +// let make the face of the profile svg + +mod background { + use core::traits::TryInto; + use karst::base::token_uris::traits::color::karstColors; + use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; + + #[derive(Drop)] + enum BackgroundVariants { + BACKGROUND1, // 1 + BACKGROUND2, // 2 + BACKGROUND3, // 3 + BACKGROUND4, // 4 + } + + pub fn backgroundSvgStart() -> ByteArray { + getBackgroundVariant(BackgroundVariants::BACKGROUND2) + } + + pub fn getBackgroundVariant(backgroundVariant: BackgroundVariants) -> ByteArray { + let mut decidedbackground: ByteArray = Default::default(); + match backgroundVariant { + BackgroundVariants::BACKGROUND1 => { + decidedbackground = + "" + }, + BackgroundVariants::BACKGROUND2 => { + decidedbackground = + "" + }, + BackgroundVariants::BACKGROUND3 => { + decidedbackground = + "" + }, + BackgroundVariants::BACKGROUND4 => { + decidedbackground = + "" + }, + } + decidedbackground + } +} diff --git a/src/base/token_uris/traits/beard.cairo b/src/base/token_uris/traits/beard.cairo new file mode 100644 index 0000000..d9af2b7 --- /dev/null +++ b/src/base/token_uris/traits/beard.cairo @@ -0,0 +1,47 @@ +// let make the face of the profile svg + +mod beard { + use core::traits::TryInto; + use karst::base::token_uris::traits::color::karstColors; + use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; + + #[derive(Drop)] + enum BeardVariants { + Beard1, // 1 + Beard2, // 2 + Beard3, // 3 + Beard4, // 4 + Beard5, // 5 + } + + pub fn beardSvgStart() -> ByteArray { + getBeardvariant(BeardVariants::Beard3) + } + + pub fn getBeardvariant(glassVariant: BeardVariants) -> ByteArray { + let mut decidedBeard: ByteArray = Default::default(); + match glassVariant { + BeardVariants::Beard1 => { + decidedBeard = + "" + }, + BeardVariants::Beard2 => { + decidedBeard = + "" + }, + BeardVariants::Beard3 => { + decidedBeard = + "" + }, + BeardVariants::Beard4 => { + decidedBeard = + "" + }, + BeardVariants::Beard5 => { + decidedBeard = + "" + } + } + decidedBeard + } +} diff --git a/src/base/token_uris/traits/cloth.cairo b/src/base/token_uris/traits/cloth.cairo new file mode 100644 index 0000000..ca29800 --- /dev/null +++ b/src/base/token_uris/traits/cloth.cairo @@ -0,0 +1,48 @@ +// let make the face of the profile svg + +mod cloth { + use core::traits::TryInto; + use karst::base::token_uris::traits::color::karstColors; + use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; + + #[derive(Drop)] + enum ClothVariants { + BlACKCOLLARSHIRT, // 1 + BLACKSHIRT, // 2 + COLLARSHIRT, // 3 + PINKTSHIRT, // 4 + TANKTOP, // 5 + } + + pub fn clothSvgStart() -> ByteArray { + getClothvariant(ClothVariants::BlACKCOLLARSHIRT) + } + + pub fn getClothvariant(clothVariant: ClothVariants) -> ByteArray { + let mut decidedCloth: ByteArray = Default::default(); + match clothVariant { + ClothVariants::BlACKCOLLARSHIRT => { + decidedCloth = + "" + }, + ClothVariants::BLACKSHIRT // 2 + => { + decidedCloth = + "" + }, + ClothVariants::COLLARSHIRT => { + decidedCloth = + "" + }, + ClothVariants::PINKTSHIRT => { + decidedCloth = + "" + }, + ClothVariants::TANKTOP => { + decidedCloth = + "" + } + } + decidedCloth + } +} diff --git a/src/base/token_uris/traits/color.cairo b/src/base/token_uris/traits/color.cairo new file mode 100644 index 0000000..10fa2b9 --- /dev/null +++ b/src/base/token_uris/traits/color.cairo @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT + +mod karstColors { + pub const baseGreen: felt252 = '#A0D170'; + pub const basePink: felt252 = '#FFD2DD'; + pub const basePurple: felt252 = '#EAD7FF'; + pub const baseBlue: felt252 = '#D9E0FF'; + pub const baseGold: felt252 = '#F8C944'; + + pub const lightGreen: felt252 = '#F4FFDC'; + pub const lightPink: felt252 = '#FFE7F0'; + pub const lightPurple: felt252 = '#F3EAFF'; + pub const lightBlue: felt252 = '#ECF0FF'; + pub const lightGold: felt252 = '#FFEE93'; + + pub const darkGreen: felt252 = '#93A97D'; + pub const darkPink: felt252 = '#EAAEC7'; + pub const darkPurple: felt252 = '#C3B3D5'; + pub const darkBlue: felt252 = '#ACB5DD'; + pub const darkGold: felt252 = '#B96326'; + + pub const dark: felt252 = '#575757'; + pub const gray: felt252 = '#DBDBDB'; + pub const lightGray: felt252 = '#EAEAEA'; + pub const white: felt252 = '#FFF'; + pub const black: felt252 = '#000'; + + pub const tears: felt252 = '#E3F7FF'; + pub const heartEyes: felt252 = '#FF88A5'; + pub const tongue: felt252 = '#FFDFE7'; + pub const bubbleGum: felt252 = '#FFCFEC'; +} diff --git a/src/base/token_uris/traits/eyeacessory.cairo b/src/base/token_uris/traits/eyeacessory.cairo new file mode 100644 index 0000000..53c9ef9 --- /dev/null +++ b/src/base/token_uris/traits/eyeacessory.cairo @@ -0,0 +1,47 @@ +// let make the face of the profile svg + +mod eyeacessory { + use core::traits::TryInto; + use karst::base::token_uris::traits::color::karstColors; + use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; + + #[derive(Drop)] + enum EyeAcessoryVariants { + BALL, // 1 + BLACKSTUD, // 2 + CIRCULAR, // 3 + CROSS, // 4 + SPEAR, // 5 + } + + pub fn eyeacessorySvgStart() -> ByteArray { + getacessoryvariant(EyeAcessoryVariants::CIRCULAR) + } + + pub fn getacessoryvariant(eyeAcessoryVariant: EyeAcessoryVariants) -> ByteArray { + let mut decidedAcessory: ByteArray = Default::default(); + match eyeAcessoryVariant { + EyeAcessoryVariants::BALL => { + decidedAcessory = + "" + }, + EyeAcessoryVariants::BLACKSTUD => { + decidedAcessory = + "" + }, + EyeAcessoryVariants::CIRCULAR => { + decidedAcessory = + "" + }, + EyeAcessoryVariants::CROSS => { + decidedAcessory = + "" + }, + EyeAcessoryVariants::SPEAR => { + decidedAcessory = + "" + } + } + decidedAcessory + } +} diff --git a/src/base/token_uris/traits/eyebrows.cairo b/src/base/token_uris/traits/eyebrows.cairo new file mode 100644 index 0000000..1227da7 --- /dev/null +++ b/src/base/token_uris/traits/eyebrows.cairo @@ -0,0 +1,47 @@ +// let make the face of the profile svg + +mod eyebrows { + use core::traits::TryInto; + use karst::base::token_uris::traits::color::karstColors; + use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; + + #[derive(Drop)] + enum EyebrowsVariants { + EYEBROW1, // 1 + EYEBROW2, // 2 + EYEBROW3, // 3 + EYEBROW4, // 4 + EYEBROW5, // 5 + } + + pub fn eyebrowsSvgStart() -> ByteArray { + geteyebrowsvariant(EyebrowsVariants::EYEBROW3) + } + + pub fn geteyebrowsvariant(glassVariant: EyebrowsVariants) -> ByteArray { + let mut decidedEyebrow: ByteArray = Default::default(); + match glassVariant { + EyebrowsVariants::EYEBROW1 => { + decidedEyebrow = + "" + }, + EyebrowsVariants::EYEBROW2 => { + decidedEyebrow = + "" + }, + EyebrowsVariants::EYEBROW3 => { + decidedEyebrow = + "" + }, + EyebrowsVariants::EYEBROW4 => { + decidedEyebrow = + "" + }, + EyebrowsVariants::EYEBROW5 => { + decidedEyebrow = + "" + } + } + decidedEyebrow + } +} diff --git a/src/base/token_uris/traits/eyecolor.cairo b/src/base/token_uris/traits/eyecolor.cairo new file mode 100644 index 0000000..78c6ac8 --- /dev/null +++ b/src/base/token_uris/traits/eyecolor.cairo @@ -0,0 +1,47 @@ +// let make the face of the profile svg + +mod eyecolor { + use core::traits::TryInto; + use karst::base::token_uris::traits::color::karstColors; + use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; + + #[derive(Drop)] + enum EyeColorVariants { + BLUE, // 1 + GREEN, // 2 + ORANGE, // 3 + RED, // 4 + SATORANGE, // 5 + } + + pub fn eyecolorSvgStart() -> ByteArray { + geteyecolorvariant(EyeColorVariants::RED) + } + + pub fn geteyecolorvariant(eyeColorVariant: EyeColorVariants) -> ByteArray { + let mut decidedcolor: ByteArray = Default::default(); + match eyeColorVariant { + EyeColorVariants::BLUE => { + decidedcolor = + "" + }, + EyeColorVariants::GREEN => { + decidedcolor = + "" + }, + EyeColorVariants::ORANGE => { + decidedcolor = + "" + }, + EyeColorVariants::RED => { + decidedcolor = + "" + }, + EyeColorVariants::SATORANGE => { + decidedcolor = + "" + } + } + decidedcolor + } +} diff --git a/src/base/token_uris/traits/follow.cairo b/src/base/token_uris/traits/follow.cairo new file mode 100644 index 0000000..46bbc81 --- /dev/null +++ b/src/base/token_uris/traits/follow.cairo @@ -0,0 +1,23 @@ +mod follow { + use core::array::ArrayTrait; + use karst::base::utils::base64_extended::convert_into_byteArray; + use karst::base::token_uris::traits::color::karstColors; + + pub fn get_svg_follow(follow_token_id: u256) -> ByteArray { + let mut svg = ArrayTrait::::new(); + let color_code = get_random_color(follow_token_id); + /// TODO chnage the circle svg to desired svg + svg.append(' '); + convert_into_byteArray(ref svg) + } + + fn get_random_color(local_name: u256) -> felt252 { + // TODO select the random color + karstColors::basePink + } +} diff --git a/src/base/token_uris/traits/glass.cairo b/src/base/token_uris/traits/glass.cairo new file mode 100644 index 0000000..8ae34c8 --- /dev/null +++ b/src/base/token_uris/traits/glass.cairo @@ -0,0 +1,48 @@ +// let make the face of the profile svg + +mod glass { + use core::traits::TryInto; + use karst::base::token_uris::traits::color::karstColors; + use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; + + #[derive(Drop)] + enum GlassVariants { + CIRCULARLENSDARKSHADES, // 1 + DARKSHADES, // 2 + EYEPATCH, // 3 + PHOTOSNIPER, // 4 + VRSET, // 5 + } + + pub fn glassSvgStart() -> ByteArray { + getGlassvariant(GlassVariants::EYEPATCH) + } + + + pub fn getGlassvariant(glassVariant: GlassVariants) -> ByteArray { + let mut decidedGlass: ByteArray = Default::default(); + match glassVariant { + GlassVariants::CIRCULARLENSDARKSHADES => { + decidedGlass = + "" + }, + GlassVariants::DARKSHADES => { + decidedGlass = + "" + }, + GlassVariants::EYEPATCH => { + decidedGlass = + "" + }, + GlassVariants::PHOTOSNIPER => { + decidedGlass = + "" + }, + GlassVariants::VRSET => { + decidedGlass = + "" + } + } + decidedGlass + } +} diff --git a/src/base/token_uris/traits/handle.cairo b/src/base/token_uris/traits/handle.cairo new file mode 100644 index 0000000..6946fbc --- /dev/null +++ b/src/base/token_uris/traits/handle.cairo @@ -0,0 +1,23 @@ +mod handle { + use core::array::ArrayTrait; + use karst::base::utils::base64_extended::convert_into_byteArray; + use karst::base::token_uris::traits::color::karstColors; + + pub fn get_svg_handle(token_id: u256, local_name: felt252, namespace: felt252) -> ByteArray { + let mut svg = ArrayTrait::::new(); + let color_code = get_random_color(local_name); + /// TODO chnage the circle svg to desired svg + svg.append(' '); + convert_into_byteArray(ref svg) + } + + fn get_random_color(local_name: felt252) -> felt252 { + // TODO select the random color + karstColors::basePink + } +} diff --git a/src/base/token_uris/traits/head.cairo b/src/base/token_uris/traits/head.cairo new file mode 100644 index 0000000..147630a --- /dev/null +++ b/src/base/token_uris/traits/head.cairo @@ -0,0 +1,118 @@ +// let make the face of the profile svg + +mod head { + use core::traits::TryInto; + use karst::base::token_uris::traits::color::karstColors; + use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; + + #[derive(Drop)] + enum FaceVariants { + HEAD1NEUTRAL1, // 1 + HEAD1NEUTRAL2, //2 + HEAD1SAD, // 3 + HEAD1SMILE, // 4 + HEAD2NEUTRAL1, // 5 + HEAD2NEUTRAL2, + HEAD2SAD, + HEAD2SMILE, + HEAD3NEUTRAL1, + HEAD3SAD, + HEAD3SMILE, + HEAD4NEUTRAL1, + HEAD4NEUTRAL2, + HEAD4SAD, + HEAD4SMILE, + HEAD5NEUTRAL1, + HEAD5NEUTRAL2, + HEAD5SAD, + HEAD5SMILE, + } + + pub fn faceSvgStart() -> ByteArray { + getHeadvariant(FaceVariants::HEAD5SMILE) + } + + + pub fn getHeadvariant(faceVariant: FaceVariants) -> ByteArray { + let mut decidedFace: ByteArray = Default::default(); + match faceVariant { + FaceVariants::HEAD1NEUTRAL1 => { + decidedFace = + "" + }, + FaceVariants::HEAD1NEUTRAL2 => { + decidedFace = + "" + }, + FaceVariants::HEAD1SAD => { + decidedFace = + "" + }, + FaceVariants::HEAD1SMILE => { + decidedFace = + "" + }, + FaceVariants::HEAD2NEUTRAL1 => { + decidedFace = + "" + }, + FaceVariants::HEAD2NEUTRAL2 => { + decidedFace = + ""; + }, + FaceVariants::HEAD2SAD => { + decidedFace = + ""; + }, + FaceVariants::HEAD2SMILE => { + decidedFace = + ""; + }, + FaceVariants::HEAD3NEUTRAL1 => { + decidedFace = + ""; + }, + FaceVariants::HEAD3SAD => { + decidedFace = + ""; + }, + FaceVariants::HEAD3SMILE => { + decidedFace = + ""; + }, + FaceVariants::HEAD4NEUTRAL1 => { + decidedFace = + "" + }, + FaceVariants::HEAD4NEUTRAL2 => { + decidedFace = + "" + }, + FaceVariants::HEAD4SAD => { + decidedFace = + "" + }, + FaceVariants::HEAD4SMILE => { + decidedFace = + "" + }, + FaceVariants::HEAD5NEUTRAL1 => { + decidedFace = + "" + }, + FaceVariants::HEAD5NEUTRAL2 => { + decidedFace = + "" + }, + FaceVariants::HEAD5SAD => { + decidedFace = + "" + }, + FaceVariants::HEAD5SMILE => { + decidedFace = + "" + }, + } + return decidedFace; + } +} diff --git a/src/base/token_uris/traits/profile.cairo b/src/base/token_uris/traits/profile.cairo new file mode 100644 index 0000000..3bff74a --- /dev/null +++ b/src/base/token_uris/traits/profile.cairo @@ -0,0 +1,20 @@ +mod ProfileSvg { + use karst::base::token_uris::traits::color::karstColors; + use karst::base::token_uris::traits::head::head::faceSvgStart; + use karst::base::token_uris::traits::glass::glass::glassSvgStart; + use karst::base::token_uris::traits::beard::beard::beardSvgStart; + use karst::base::token_uris::traits::cloth::cloth::clothSvgStart; + use karst::base::token_uris::traits::background::background::backgroundSvgStart; + + pub fn gen_profile_svg() -> ByteArray { + let mut profilesvg: ByteArray = + ""; + profilesvg.append(@backgroundSvgStart()); + profilesvg.append(@faceSvgStart()); + profilesvg.append(@glassSvgStart()); + profilesvg.append(@beardSvgStart()); + profilesvg.append(@clothSvgStart()); + profilesvg.append(@""); + profilesvg + } +} diff --git a/src/base/utils.cairo b/src/base/utils.cairo index 8a90e4f..5145ad3 100644 --- a/src/base/utils.cairo +++ b/src/base/utils.cairo @@ -1,2 +1,3 @@ mod byte_array_extra; mod hubrestricted; +mod base64_extended; diff --git a/src/base/utils/base64_extended.cairo b/src/base/utils/base64_extended.cairo new file mode 100644 index 0000000..05acc08 --- /dev/null +++ b/src/base/utils/base64_extended.cairo @@ -0,0 +1,36 @@ +use core::serde::Serde; +use core::array::ArrayTrait; +use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; +use alexandria_encoding::base64::{Base64UrlEncoder}; + +pub fn get_base64_encode(res: ByteArray) -> ByteArray { + let mut res_arr_u8 = ArrayTrait::::new(); + let mut i = 0; + while i < res + .len() { + let mut res_data = res.at(i); + res_arr_u8.append(res_data.unwrap()); + i += 1; + }; + let mut encoded_val = Base64UrlEncoder::encode(res_arr_u8); + let mut res_final: ByteArray = Default::default(); + let mut j = 0; + while j < encoded_val + .len() { + let encoded_val_data = encoded_val.at(j); + res_final.append_byte(*encoded_val_data); + j += 1; + }; + res_final +} + +pub fn convert_into_byteArray(ref svg: Array) -> ByteArray { + let mut res: ByteArray = Default::default(); + // converting felt252 array to byte array + while (!svg.is_empty()) { + let each_felt: felt252 = svg.pop_front().unwrap(); + let word: ByteArray = each_felt.try_into().unwrap(); + res.append(@word); + }; + res +}