flipbip_scene_1.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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. const char* passphrase_text) {
  267. model->page = 0;
  268. model->mnemonic_only = false;
  269. model->strength = strength;
  270. model->coin = coin;
  271. model->overwrite = overwrite;
  272. // Allocate memory for mnemonic
  273. char* mnemonic = malloc(TEXT_BUFFER_SIZE);
  274. memzero(mnemonic, TEXT_BUFFER_SIZE);
  275. // Check if the mnemonic key & data is already saved in persistent storage, or overwrite is true
  276. if(overwrite || (!flipbip_has_settings(true) && !flipbip_has_settings(false))) {
  277. // Generate a random mnemonic using trezor-crypto
  278. const char* mnemonic_gen = mnemonic_generate(strength);
  279. // Save the mnemonic to persistent storage
  280. if(!flipbip_save_settings_secure(mnemonic_gen)) return 1; // 1 = save error
  281. // Clear the generated mnemonic from memory
  282. mnemonic_clear();
  283. model->mnemonic_only = true;
  284. }
  285. // Load the mnemonic from persistent storage
  286. if(!flipbip_load_settings_secure(mnemonic)) return 2; // 2 = load error
  287. model->mnemonic = mnemonic;
  288. // Check if the mnemonic is valid
  289. if(mnemonic_check(model->mnemonic) == 0) return 3; // 3 = mnemonic check error
  290. // if we are only generating the mnemonic, return
  291. if(model->mnemonic_only) {
  292. return -1; // -1 = mnemonic only, return from parent
  293. }
  294. // test mnemonic
  295. //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";
  296. // Generate a BIP39 seed from the mnemonic
  297. mnemonic_to_seed(model->mnemonic, passphrase_text, model->seed, 0);
  298. // Generate a BIP32 root HD node from the mnemonic
  299. HDNode* root = malloc(sizeof(HDNode));
  300. hdnode_from_seed(model->seed, 64, SECP256K1_NAME, root);
  301. // buffer for key serialization
  302. const size_t buflen = 128;
  303. char buf[128 + 1];
  304. // coin info
  305. // bip44_coin, xprv_version, xpub_version, addr_version, wif_version, addr_format
  306. uint32_t coin_info[6] = {0};
  307. for(size_t i = 0; i < 6; i++) {
  308. coin_info[i] = COIN_INFO_ARRAY[coin][i];
  309. }
  310. // root
  311. uint32_t fingerprint = 0;
  312. hdnode_serialize_private(root, fingerprint, coin_info[1], buf, buflen);
  313. char* xprv_root = malloc(buflen + 1);
  314. strncpy(xprv_root, buf, buflen);
  315. model->xprv_root = xprv_root;
  316. HDNode* node = root;
  317. // purpose m/44'
  318. fingerprint = hdnode_fingerprint(node);
  319. hdnode_private_ckd_prime(node, DERIV_PURPOSE); // purpose
  320. // coin m/44'/0' or m/44'/60'
  321. fingerprint = hdnode_fingerprint(node);
  322. hdnode_private_ckd_prime(node, coin_info[0]); // coin
  323. // account m/44'/0'/0' or m/44'/60'/0'
  324. fingerprint = hdnode_fingerprint(node);
  325. hdnode_private_ckd_prime(node, DERIV_ACCOUNT); // account
  326. hdnode_serialize_private(node, fingerprint, coin_info[1], buf, buflen);
  327. char* xprv_acc = malloc(buflen + 1);
  328. strncpy(xprv_acc, buf, buflen);
  329. model->xprv_account = xprv_acc;
  330. hdnode_serialize_public(node, fingerprint, coin_info[2], buf, buflen);
  331. char* xpub_acc = malloc(buflen + 1);
  332. strncpy(xpub_acc, buf, buflen);
  333. model->xpub_account = xpub_acc;
  334. // external/internal (change) m/44'/0'/0'/0 or m/44'/60'/0'/0
  335. fingerprint = hdnode_fingerprint(node);
  336. hdnode_private_ckd(node, DERIV_CHANGE); // external/internal (change)
  337. hdnode_serialize_private(node, fingerprint, coin_info[1], buf, buflen);
  338. char* xprv_ext = malloc(buflen + 1);
  339. strncpy(xprv_ext, buf, buflen);
  340. model->xprv_extended = xprv_ext;
  341. hdnode_serialize_public(node, fingerprint, coin_info[2], buf, buflen);
  342. char* xpub_ext = malloc(buflen + 1);
  343. strncpy(xpub_ext, buf, buflen);
  344. model->xpub_extended = xpub_ext;
  345. model->node = node;
  346. model->page = 1;
  347. #if USE_BIP39_CACHE
  348. // Clear the BIP39 cache
  349. bip39_cache_clear();
  350. #endif
  351. // 0 = success
  352. return 0;
  353. }
  354. bool flipbip_scene_1_input(InputEvent* event, void* context) {
  355. furi_assert(context);
  356. FlipBipScene1* instance = context;
  357. // Ignore input if busy
  358. // if(s_busy) {
  359. // return false;
  360. // }
  361. if(event->type == InputTypeRelease) {
  362. switch(event->key) {
  363. case InputKeyBack:
  364. with_view_model(
  365. instance->view,
  366. FlipBipScene1Model * model,
  367. {
  368. UNUSED(model);
  369. instance->callback(FlipBipCustomEventScene1Back, instance->context);
  370. },
  371. true);
  372. break;
  373. case InputKeyRight:
  374. case InputKeyDown:
  375. case InputKeyOk:
  376. with_view_model(
  377. instance->view,
  378. FlipBipScene1Model * model,
  379. {
  380. //UNUSED(model);
  381. model->page = (model->page + 1) % 14;
  382. if(model->page == 0) {
  383. model->page = 1;
  384. }
  385. },
  386. true);
  387. break;
  388. case InputKeyLeft:
  389. case InputKeyUp:
  390. with_view_model(
  391. instance->view,
  392. FlipBipScene1Model * model,
  393. {
  394. //UNUSED(model);
  395. model->page = (model->page - 1) % 14;
  396. if(model->page == 0) {
  397. model->page = 13;
  398. }
  399. },
  400. true);
  401. break;
  402. case InputKeyMAX:
  403. break;
  404. }
  405. }
  406. return true;
  407. }
  408. void flipbip_scene_1_exit(void* context) {
  409. furi_assert(context);
  410. FlipBipScene1* instance = (FlipBipScene1*)context;
  411. with_view_model(
  412. instance->view,
  413. FlipBipScene1Model * model,
  414. {
  415. model->page = 0;
  416. model->strength = 0;
  417. model->coin = FlipBipCoinBTC0;
  418. memzero(model->seed, 64);
  419. // if mnemonic_only is true, then we don't need to free the data here
  420. if(!model->mnemonic_only) {
  421. memzero((void*)model->mnemonic, strlen(model->mnemonic));
  422. free((void*)model->mnemonic);
  423. memzero((void*)model->node, sizeof(HDNode));
  424. free((void*)model->node);
  425. memzero((void*)model->xprv_root, strlen(model->xprv_root));
  426. memzero((void*)model->xprv_account, strlen(model->xprv_account));
  427. memzero((void*)model->xpub_account, strlen(model->xpub_account));
  428. memzero((void*)model->xprv_extended, strlen(model->xprv_extended));
  429. memzero((void*)model->xpub_extended, strlen(model->xpub_extended));
  430. free((void*)model->xprv_root);
  431. free((void*)model->xprv_account);
  432. free((void*)model->xpub_account);
  433. free((void*)model->xprv_extended);
  434. free((void*)model->xpub_extended);
  435. }
  436. },
  437. true);
  438. flipbip_scene_1_clear_text();
  439. }
  440. void flipbip_scene_1_enter(void* context) {
  441. furi_assert(context);
  442. FlipBipScene1* instance = (FlipBipScene1*)context;
  443. FlipBip* app = instance->context;
  444. // BIP39 Strength setting
  445. int strength = 256; // FlipBipStrength256 // 24 words (256 bit)
  446. if(app->bip39_strength == FlipBipStrength128) {
  447. strength = 128; // 12 words (128 bit)
  448. } else if(app->bip39_strength == FlipBipStrength192) {
  449. strength = 192; // 18 words (192 bit)
  450. }
  451. // BIP39 Passphrase setting
  452. const char* passphrase_text = "";
  453. if(app->passphrase == FlipBipPassphraseOn && strlen(app->passphrase_text) > 0) {
  454. passphrase_text = app->passphrase_text;
  455. }
  456. // BIP44 Coin setting
  457. uint32_t coin = app->bip44_coin;
  458. // coin_name, derivation_path
  459. s_derivation_text = COIN_TEXT_ARRAY[coin][1];
  460. // Overwrite the saved seed with a new one setting
  461. bool overwrite = app->overwrite_saved_seed != 0;
  462. if(overwrite) {
  463. s_derivation_text = TEXT_NEW_WALLET;
  464. }
  465. flipbip_play_happy_bump(app);
  466. flipbip_led_set_rgb(app, 255, 0, 0);
  467. with_view_model(
  468. instance->view,
  469. FlipBipScene1Model * model,
  470. {
  471. // s_busy = true;
  472. const int status =
  473. flipbip_scene_1_model_init(model, strength, coin, overwrite, passphrase_text);
  474. // nonzero status, free the mnemonic
  475. if(status != 0) {
  476. memzero((void*)model->mnemonic, strlen(model->mnemonic));
  477. free((void*)model->mnemonic);
  478. }
  479. // if error, set the error message
  480. if(status == 1) {
  481. model->mnemonic = "ERROR:,Save error";
  482. model->page = 2;
  483. } else if(status == 2) {
  484. model->mnemonic = "ERROR:,Load error";
  485. model->page = 2;
  486. } else if(status == 3) {
  487. model->mnemonic = "ERROR:,Mnemonic check failed";
  488. model->page = 2;
  489. }
  490. // s_busy = false;
  491. // if overwrite is set and mnemonic generated, return from scene immediately
  492. if(status == -1) {
  493. instance->callback(FlipBipCustomEventScene1Back, instance->context);
  494. }
  495. },
  496. true);
  497. }
  498. FlipBipScene1* flipbip_scene_1_alloc() {
  499. FlipBipScene1* instance = malloc(sizeof(FlipBipScene1));
  500. instance->view = view_alloc();
  501. view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(FlipBipScene1Model));
  502. view_set_context(instance->view, instance); // furi_assert crashes in events without this
  503. view_set_draw_callback(instance->view, (ViewDrawCallback)flipbip_scene_1_draw);
  504. view_set_input_callback(instance->view, flipbip_scene_1_input);
  505. view_set_enter_callback(instance->view, flipbip_scene_1_enter);
  506. view_set_exit_callback(instance->view, flipbip_scene_1_exit);
  507. return instance;
  508. }
  509. void flipbip_scene_1_free(FlipBipScene1* instance) {
  510. furi_assert(instance);
  511. with_view_model(
  512. instance->view, FlipBipScene1Model * model, { UNUSED(model); }, true);
  513. flipbip_scene_1_clear_text();
  514. view_free(instance->view);
  515. free(instance);
  516. }
  517. View* flipbip_scene_1_get_view(FlipBipScene1* instance) {
  518. furi_assert(instance);
  519. return instance->view;
  520. }