flipbip_scene_1.c 20 KB

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