flipbip_scene_1.c 20 KB

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