flipbip_scene_1.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. #include "../flipbip.h"
  2. #include <furi.h>
  3. #include <furi_hal.h>
  4. #include <input/input.h>
  5. #include <gui/elements.h>
  6. //#include <dolphin/dolphin.h>
  7. #include <storage/storage.h>
  8. #include "FlipBIP_icons.h"
  9. #include "../helpers/flipbip_haptic.h"
  10. #include "../helpers/flipbip_led.h"
  11. #include "../helpers/flipbip_string.h"
  12. #include "../helpers/flipbip_file.h"
  13. #include <string.h>
  14. #include "../crypto/rand.h"
  15. #include "../crypto/bip32.h"
  16. #include "../crypto/bip39.h"
  17. #include "../crypto/curves.h"
  18. #include "../crypto/memzero.h"
  19. #define DERIV_PURPOSE 44
  20. #define DERIV_ACCOUNT 0
  21. #define DERIV_CHANGE 0
  22. #define TEXT_LOADING "Loading..."
  23. #define TEXT_NEW_WALLET "New wallet"
  24. #define TEXT_DEFAULT_COIN "Coin"
  25. #define TEXT_RECEIVE_ADDRESS "receive address:"
  26. #define TEXT_DEFAULT_DERIV "m/44'/X'/0'/0"
  27. const char* TEXT_INFO = "-Scroll pages with up/down-"
  28. "p1,2) Mnemonic/Seed "
  29. "p3) xprv Root Key "
  30. "p4,5) xprv/xpub Accnt Keys"
  31. "p6,7) xprv/xpub Extnd Keys"
  32. "p8+) Receive Addresses ";
  33. // bip44_coin, xprv_version, xpub_version, addr_version, wif_version, addr_format
  34. const uint32_t COIN_INFO_ARRAY[3][6] = {
  35. {COIN_BTC, 0x0488ade4, 0x0488b21e, 0x00, 0x80, FlipBipCoinBTC0},
  36. {COIN_ETH, 0x0488ade4, 0x0488b21e, 0x00, 0x80, FlipBipCoinETH60},
  37. {COIN_DOGE, 0x02fac398, 0x02facafd, 0x1e, 0x9e, FlipBipCoinBTC0}};
  38. // coin_name, derivation_path
  39. const char* COIN_TEXT_ARRAY[3][2] = {
  40. {"BTC", "m/44'/0'/0'/0"},
  41. {"ETH", "m/44'/60'/0'/0"},
  42. {"DOGE", "m/44'/3'/0'/0"}};
  43. struct FlipBipScene1 {
  44. View* view;
  45. FlipBipScene1Callback callback;
  46. void* context;
  47. };
  48. typedef struct {
  49. int page;
  50. int strength;
  51. uint32_t coin;
  52. bool overwrite;
  53. bool mnemonic_only;
  54. CONFIDENTIAL const char* mnemonic;
  55. CONFIDENTIAL uint8_t seed[64];
  56. CONFIDENTIAL const HDNode* node;
  57. CONFIDENTIAL const char* xprv_root;
  58. CONFIDENTIAL const char* xprv_account;
  59. CONFIDENTIAL const char* xpub_account;
  60. CONFIDENTIAL const char* xprv_extended;
  61. CONFIDENTIAL const char* xpub_extended;
  62. } FlipBipScene1Model;
  63. static CONFIDENTIAL char s_disp_text1[30 + 1];
  64. static CONFIDENTIAL char s_disp_text2[30 + 1];
  65. static CONFIDENTIAL char s_disp_text3[30 + 1];
  66. static CONFIDENTIAL char s_disp_text4[30 + 1];
  67. static CONFIDENTIAL char s_disp_text5[30 + 1];
  68. static CONFIDENTIAL char s_disp_text6[30 + 1];
  69. static const char* s_derivation_text = TEXT_DEFAULT_DERIV;
  70. //static bool s_busy = false;
  71. void flipbip_scene_1_set_callback(
  72. FlipBipScene1* instance,
  73. FlipBipScene1Callback callback,
  74. void* context) {
  75. furi_assert(instance);
  76. furi_assert(callback);
  77. instance->callback = callback;
  78. instance->context = context;
  79. }
  80. static void flipbip_scene_1_draw_generic(const char* text, size_t line_len) {
  81. // Split the text into parts
  82. for(size_t si = 1; si <= 6; si++) {
  83. char* ptr = NULL;
  84. if(si == 1)
  85. ptr = s_disp_text1;
  86. else if(si == 2)
  87. ptr = s_disp_text2;
  88. else if(si == 3)
  89. ptr = s_disp_text3;
  90. else if(si == 4)
  91. ptr = s_disp_text4;
  92. else if(si == 5)
  93. ptr = s_disp_text5;
  94. else if(si == 6)
  95. ptr = s_disp_text6;
  96. memzero(ptr, 30 + 1);
  97. if(line_len > 30) {
  98. strncpy(ptr, text + ((si - 1) * 30), 30);
  99. } else {
  100. strncpy(ptr, text + ((si - 1) * line_len), line_len);
  101. }
  102. }
  103. }
  104. static void flipbip_scene_1_draw_mnemonic(const char* mnemonic) {
  105. // Delineate sections of the mnemonic every 4 words
  106. char* mnemonic_working = malloc(strlen(mnemonic) + 1);
  107. strcpy(mnemonic_working, mnemonic);
  108. int word = 0;
  109. for(size_t i = 0; i < strlen(mnemonic_working); i++) {
  110. if(mnemonic_working[i] == ' ') {
  111. word++;
  112. if(word % 4 == 0) {
  113. mnemonic_working[i] = ',';
  114. }
  115. }
  116. }
  117. // Split the mnemonic into parts
  118. char* mnemonic_part = flipbip_strtok(mnemonic_working, ",");
  119. int mi = 0;
  120. while(mnemonic_part != NULL) {
  121. char* ptr = NULL;
  122. mi++;
  123. if(mi == 1)
  124. ptr = s_disp_text1;
  125. else if(mi == 2)
  126. ptr = s_disp_text2;
  127. else if(mi == 3)
  128. ptr = s_disp_text3;
  129. else if(mi == 4)
  130. ptr = s_disp_text4;
  131. else if(mi == 5)
  132. ptr = s_disp_text5;
  133. else if(mi == 6)
  134. ptr = s_disp_text6;
  135. memzero(ptr, 30 + 1);
  136. if(strlen(mnemonic_part) > 30) {
  137. strncpy(ptr, mnemonic_part, 30);
  138. } else {
  139. strncpy(ptr, mnemonic_part, strlen(mnemonic_part));
  140. }
  141. mnemonic_part = flipbip_strtok(NULL, ",");
  142. }
  143. // Free the working mnemonic memory
  144. memzero(mnemonic_working, strlen(mnemonic_working));
  145. free(mnemonic_working);
  146. }
  147. static void flipbip_scene_1_draw_seed(FlipBipScene1Model* const model) {
  148. char* seed_working = malloc(64 * 2 + 1);
  149. // Convert the seed to a hex string
  150. flipbip_btox(model->seed, 64, seed_working);
  151. flipbip_scene_1_draw_generic(seed_working, 22);
  152. // Free the working seed memory
  153. memzero(seed_working, sizeof(seed_working));
  154. free(seed_working);
  155. }
  156. static void
  157. flipbip_scene_1_draw_address(const HDNode* node, uint32_t addr_type, uint32_t addr_index) {
  158. //s_busy = true;
  159. // buffer for key serialization
  160. const size_t buflen = 128;
  161. char buf[128 + 1];
  162. HDNode* addr_node = malloc(sizeof(HDNode));
  163. memcpy(addr_node, node, sizeof(HDNode));
  164. hdnode_private_ckd(addr_node, addr_index);
  165. hdnode_fill_public_key(addr_node);
  166. // coin info
  167. // bip44_coin, xprv_version, xpub_version, addr_version, wif_version, addr_format
  168. uint32_t coin_info[6] = {0};
  169. for(size_t i = 0; i < 6; i++) {
  170. coin_info[i] = COIN_INFO_ARRAY[addr_type][i];
  171. }
  172. if(coin_info[5] == FlipBipCoinBTC0) { // BTC / DOGE style address
  173. // BTC / DOGE style address
  174. ecdsa_get_address(
  175. addr_node->public_key, coin_info[3], HASHER_SHA2_RIPEMD, HASHER_SHA2D, buf, buflen);
  176. char* address = malloc(buflen + 1);
  177. strncpy(address, buf, buflen);
  178. flipbip_scene_1_draw_generic(address, 12);
  179. memzero(address, buflen + 1);
  180. free(address);
  181. //ecdsa_get_wif(addr_node->private_key, WIF_VERSION, HASHER_SHA2D, buf, buflen);
  182. //char *wif = malloc(buflen + 1);
  183. //strncpy(wif, buf, buflen);
  184. } else if(coin_info[5] == FlipBipCoinETH60) { // ETH
  185. // ETH style address
  186. hdnode_get_ethereum_pubkeyhash(addr_node, (uint8_t*)buf);
  187. char* address = malloc(42 + 1);
  188. memcpy(address, "0x", 2);
  189. // Convert the hash to a hex string
  190. flipbip_btox((uint8_t*)buf, 20, address + 2);
  191. flipbip_scene_1_draw_generic(address, 12);
  192. memzero(address, 42 + 1);
  193. free(address);
  194. }
  195. memzero(addr_node, sizeof(HDNode));
  196. free(addr_node);
  197. //s_busy = false;
  198. }
  199. static void flipbip_scene_1_clear_text() {
  200. memzero((void*)s_disp_text1, 30 + 1);
  201. memzero((void*)s_disp_text2, 30 + 1);
  202. memzero((void*)s_disp_text3, 30 + 1);
  203. memzero((void*)s_disp_text4, 30 + 1);
  204. memzero((void*)s_disp_text5, 30 + 1);
  205. memzero((void*)s_disp_text6, 30 + 1);
  206. }
  207. void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {
  208. //UNUSED(model);
  209. canvas_clear(canvas);
  210. canvas_set_color(canvas, ColorBlack);
  211. flipbip_scene_1_clear_text();
  212. if(model->page == 1) {
  213. flipbip_scene_1_draw_generic(TEXT_INFO, 27);
  214. } else if(model->page == 2) {
  215. flipbip_scene_1_draw_mnemonic(model->mnemonic);
  216. } else if(model->page == 3) {
  217. flipbip_scene_1_draw_seed(model);
  218. } else if(model->page == 4) {
  219. flipbip_scene_1_draw_generic(model->xprv_root, 20);
  220. } else if(model->page == 5) {
  221. flipbip_scene_1_draw_generic(model->xprv_account, 20);
  222. } else if(model->page == 6) {
  223. flipbip_scene_1_draw_generic(model->xpub_account, 20);
  224. } else if(model->page == 7) {
  225. flipbip_scene_1_draw_generic(model->xprv_extended, 20);
  226. } else if(model->page == 8) {
  227. flipbip_scene_1_draw_generic(model->xpub_extended, 20);
  228. } else if(model->page >= 9 && model->page <= 13) {
  229. flipbip_scene_1_draw_address(model->node, model->coin, model->page - 9);
  230. }
  231. if(model->page == 0) {
  232. canvas_set_font(canvas, FontPrimary);
  233. canvas_draw_str(canvas, 1, 10, TEXT_LOADING);
  234. canvas_draw_str(canvas, 6, 30, s_derivation_text);
  235. canvas_draw_icon(canvas, 86, 25, &I_Keychain_39x36);
  236. } else if(model->page >= 9 && model->page <= 13) {
  237. canvas_set_font(canvas, FontSecondary);
  238. // coin_name, derivation_path
  239. const char* receive_text = COIN_TEXT_ARRAY[model->coin][0];
  240. if(receive_text == NULL) {
  241. receive_text = TEXT_DEFAULT_COIN;
  242. }
  243. const size_t receive_len = strlen(receive_text) * 7;
  244. canvas_draw_str_aligned(canvas, 1, 2, AlignLeft, AlignTop, receive_text);
  245. canvas_draw_str_aligned(canvas, receive_len, 2, AlignLeft, AlignTop, TEXT_RECEIVE_ADDRESS);
  246. canvas_set_font(canvas, FontPrimary);
  247. canvas_draw_str(canvas, 6, 22, s_disp_text1);
  248. canvas_draw_str(canvas, 6, 34, s_disp_text2);
  249. canvas_draw_str(canvas, 6, 46, s_disp_text3);
  250. canvas_draw_str(canvas, 6, 58, s_disp_text4);
  251. } else {
  252. canvas_set_font(canvas, FontSecondary);
  253. canvas_draw_str_aligned(canvas, 1, 2, AlignLeft, AlignTop, s_disp_text1);
  254. canvas_draw_str_aligned(canvas, 1, 12, AlignLeft, AlignTop, s_disp_text2);
  255. canvas_draw_str_aligned(canvas, 1, 22, AlignLeft, AlignTop, s_disp_text3);
  256. canvas_draw_str_aligned(canvas, 1, 32, AlignLeft, AlignTop, s_disp_text4);
  257. canvas_draw_str_aligned(canvas, 1, 42, AlignLeft, AlignTop, s_disp_text5);
  258. canvas_draw_str_aligned(canvas, 1, 52, AlignLeft, AlignTop, s_disp_text6);
  259. }
  260. }
  261. static int flipbip_scene_1_model_init(
  262. FlipBipScene1Model* const model,
  263. const int strength,
  264. const uint32_t coin,
  265. const bool overwrite) {
  266. model->page = 0;
  267. model->mnemonic_only = false;
  268. model->strength = strength;
  269. model->coin = coin;
  270. model->overwrite = overwrite;
  271. // Allocate memory for mnemonic
  272. char* mnemonic = malloc(256);
  273. memzero(mnemonic, 256);
  274. // Check if the mnemonic key & data is already saved in persistent storage, or overwrite is true
  275. if(overwrite || (!flipbip_has_settings(true) && !flipbip_has_settings(false))) {
  276. // Generate a random mnemonic using trezor-crypto
  277. const char* mnemonic_gen = mnemonic_generate(strength);
  278. // Save the mnemonic to persistent storage
  279. if(!flipbip_save_settings_secure(mnemonic_gen)) return 1; // 1 = save error
  280. // Clear the generated mnemonic from memory
  281. mnemonic_clear();
  282. model->mnemonic_only = true;
  283. }
  284. // Load the mnemonic from persistent storage
  285. if(!flipbip_load_settings_secure(mnemonic)) return 2; // 2 = load error
  286. model->mnemonic = mnemonic;
  287. // Check if the mnemonic is valid
  288. if(mnemonic_check(model->mnemonic) == 0) return 3; // 3 = mnemonic check error
  289. // if we are only generating the mnemonic, return
  290. if(model->mnemonic_only) {
  291. return -1; // -1 = mnemonic only, return from parent
  292. }
  293. // test mnemonic
  294. //model->mnemonic = "wealth budget salt video delay obey neutral tail sure soda hold rubber joy movie boat raccoon tornado noise off inmate payment patch group topple";
  295. // Generate a BIP39 seed from the mnemonic
  296. mnemonic_to_seed(model->mnemonic, "", model->seed, 0);
  297. // Generate a BIP32 root HD node from the mnemonic
  298. HDNode* root = malloc(sizeof(HDNode));
  299. hdnode_from_seed(model->seed, 64, SECP256K1_NAME, root);
  300. // buffer for key serialization
  301. const size_t buflen = 128;
  302. char buf[128 + 1];
  303. // coin info
  304. // bip44_coin, xprv_version, xpub_version, addr_version, wif_version, addr_format
  305. uint32_t coin_info[6] = {0};
  306. for(size_t i = 0; i < 6; i++) {
  307. coin_info[i] = COIN_INFO_ARRAY[coin][i];
  308. }
  309. // root
  310. uint32_t fingerprint = 0;
  311. hdnode_serialize_private(root, fingerprint, coin_info[1], buf, buflen);
  312. char* xprv_root = malloc(buflen + 1);
  313. strncpy(xprv_root, buf, buflen);
  314. model->xprv_root = xprv_root;
  315. HDNode* node = root;
  316. // purpose m/44'
  317. fingerprint = hdnode_fingerprint(node);
  318. hdnode_private_ckd_prime(node, DERIV_PURPOSE); // purpose
  319. // coin m/44'/0' or m/44'/60'
  320. fingerprint = hdnode_fingerprint(node);
  321. hdnode_private_ckd_prime(node, coin_info[0]); // coin
  322. // account m/44'/0'/0' or m/44'/60'/0'
  323. fingerprint = hdnode_fingerprint(node);
  324. hdnode_private_ckd_prime(node, DERIV_ACCOUNT); // account
  325. hdnode_serialize_private(node, fingerprint, coin_info[1], buf, buflen);
  326. char* xprv_acc = malloc(buflen + 1);
  327. strncpy(xprv_acc, buf, buflen);
  328. model->xprv_account = xprv_acc;
  329. hdnode_serialize_public(node, fingerprint, coin_info[2], buf, buflen);
  330. char* xpub_acc = malloc(buflen + 1);
  331. strncpy(xpub_acc, buf, buflen);
  332. model->xpub_account = xpub_acc;
  333. // external/internal (change) m/44'/0'/0'/0 or m/44'/60'/0'/0
  334. fingerprint = hdnode_fingerprint(node);
  335. hdnode_private_ckd(node, DERIV_CHANGE); // external/internal (change)
  336. hdnode_serialize_private(node, fingerprint, coin_info[1], buf, buflen);
  337. char* xprv_ext = malloc(buflen + 1);
  338. strncpy(xprv_ext, buf, buflen);
  339. model->xprv_extended = xprv_ext;
  340. hdnode_serialize_public(node, fingerprint, coin_info[2], buf, buflen);
  341. char* xpub_ext = malloc(buflen + 1);
  342. strncpy(xpub_ext, buf, buflen);
  343. model->xpub_extended = xpub_ext;
  344. model->node = node;
  345. model->page = 1;
  346. #if USE_BIP39_CACHE
  347. // Clear the BIP39 cache
  348. bip39_cache_clear();
  349. #endif
  350. // 0 = success
  351. return 0;
  352. }
  353. bool flipbip_scene_1_input(InputEvent* event, void* context) {
  354. furi_assert(context);
  355. FlipBipScene1* instance = context;
  356. // Ignore input if busy
  357. // if(s_busy) {
  358. // return false;
  359. // }
  360. if(event->type == InputTypeRelease) {
  361. switch(event->key) {
  362. case InputKeyBack:
  363. with_view_model(
  364. instance->view,
  365. FlipBipScene1Model * model,
  366. {
  367. UNUSED(model);
  368. instance->callback(FlipBipCustomEventScene1Back, instance->context);
  369. },
  370. true);
  371. break;
  372. case InputKeyRight:
  373. case InputKeyDown:
  374. case InputKeyOk:
  375. with_view_model(
  376. instance->view,
  377. FlipBipScene1Model * model,
  378. {
  379. //UNUSED(model);
  380. model->page = (model->page + 1) % 14;
  381. if(model->page == 0) {
  382. model->page = 1;
  383. }
  384. },
  385. true);
  386. break;
  387. case InputKeyLeft:
  388. case InputKeyUp:
  389. with_view_model(
  390. instance->view,
  391. FlipBipScene1Model * model,
  392. {
  393. //UNUSED(model);
  394. model->page = (model->page - 1) % 14;
  395. if(model->page == 0) {
  396. model->page = 13;
  397. }
  398. },
  399. true);
  400. break;
  401. case InputKeyMAX:
  402. break;
  403. }
  404. }
  405. return true;
  406. }
  407. void flipbip_scene_1_exit(void* context) {
  408. furi_assert(context);
  409. FlipBipScene1* instance = (FlipBipScene1*)context;
  410. with_view_model(
  411. instance->view,
  412. FlipBipScene1Model * model,
  413. {
  414. model->page = 0;
  415. model->strength = 0;
  416. model->coin = FlipBipCoinBTC0;
  417. memzero(model->seed, 64);
  418. // if mnemonic_only is true, then we don't need to free the data here
  419. if(!model->mnemonic_only) {
  420. memzero((void*)model->mnemonic, strlen(model->mnemonic));
  421. free((void*)model->mnemonic);
  422. memzero((void*)model->node, sizeof(HDNode));
  423. free((void*)model->node);
  424. memzero((void*)model->xprv_root, strlen(model->xprv_root));
  425. memzero((void*)model->xprv_account, strlen(model->xprv_account));
  426. memzero((void*)model->xpub_account, strlen(model->xpub_account));
  427. memzero((void*)model->xprv_extended, strlen(model->xprv_extended));
  428. memzero((void*)model->xpub_extended, strlen(model->xpub_extended));
  429. free((void*)model->xprv_root);
  430. free((void*)model->xprv_account);
  431. free((void*)model->xpub_account);
  432. free((void*)model->xprv_extended);
  433. free((void*)model->xpub_extended);
  434. }
  435. },
  436. true);
  437. flipbip_scene_1_clear_text();
  438. }
  439. void flipbip_scene_1_enter(void* context) {
  440. furi_assert(context);
  441. FlipBipScene1* instance = (FlipBipScene1*)context;
  442. FlipBip* app = instance->context;
  443. // BIP39 Strength setting
  444. int strength_setting = app->bip39_strength;
  445. int strength = 256; // FlipBipStrength256 // 24 words (256 bit)
  446. if(strength_setting == FlipBipStrength128)
  447. strength = 128; // 12 words (128 bit)
  448. else if(strength_setting == FlipBipStrength192)
  449. strength = 192; // 18 words (192 bit)
  450. // BIP44 Coin setting
  451. uint32_t coin = app->bip44_coin;
  452. // coin_name, derivation_path
  453. s_derivation_text = COIN_TEXT_ARRAY[coin][1];
  454. // Overwrite the saved seed with a new one setting
  455. bool overwrite = app->overwrite_saved_seed != 0;
  456. if(overwrite) {
  457. s_derivation_text = TEXT_NEW_WALLET;
  458. }
  459. flipbip_play_happy_bump(app);
  460. flipbip_led_set_rgb(app, 255, 0, 0);
  461. with_view_model(
  462. instance->view,
  463. FlipBipScene1Model * model,
  464. {
  465. // s_busy = true;
  466. const int status = flipbip_scene_1_model_init(model, strength, coin, overwrite);
  467. // nonzero status, free the mnemonic
  468. if(status != 0) {
  469. memzero((void*)model->mnemonic, strlen(model->mnemonic));
  470. free((void*)model->mnemonic);
  471. }
  472. // if error, set the error message
  473. if(status == 1) {
  474. model->mnemonic = "ERROR:,Save error";
  475. model->page = 2;
  476. } else if(status == 2) {
  477. model->mnemonic = "ERROR:,Load error";
  478. model->page = 2;
  479. } else if(status == 3) {
  480. model->mnemonic = "ERROR:,Mnemonic check failed";
  481. model->page = 2;
  482. }
  483. // s_busy = false;
  484. // if overwrite is set and mnemonic generated, return from scene immediately
  485. if(status == -1) {
  486. instance->callback(FlipBipCustomEventScene1Back, instance->context);
  487. }
  488. },
  489. true);
  490. }
  491. FlipBipScene1* flipbip_scene_1_alloc() {
  492. FlipBipScene1* instance = malloc(sizeof(FlipBipScene1));
  493. instance->view = view_alloc();
  494. view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(FlipBipScene1Model));
  495. view_set_context(instance->view, instance); // furi_assert crashes in events without this
  496. view_set_draw_callback(instance->view, (ViewDrawCallback)flipbip_scene_1_draw);
  497. view_set_input_callback(instance->view, flipbip_scene_1_input);
  498. view_set_enter_callback(instance->view, flipbip_scene_1_enter);
  499. view_set_exit_callback(instance->view, flipbip_scene_1_exit);
  500. return instance;
  501. }
  502. void flipbip_scene_1_free(FlipBipScene1* instance) {
  503. furi_assert(instance);
  504. with_view_model(
  505. instance->view, FlipBipScene1Model * model, { UNUSED(model); }, true);
  506. flipbip_scene_1_clear_text();
  507. view_free(instance->view);
  508. free(instance);
  509. }
  510. View* flipbip_scene_1_get_view(FlipBipScene1* instance) {
  511. furi_assert(instance);
  512. return instance->view;
  513. }