@@ -17,6 +17,7 @@ import {
1717 Account ,
1818 PublicAccount ,
1919 NetworkType ,
20+ Password ,
2021} from "nem2-sdk" ;
2122
2223// internal dependencies
@@ -25,14 +26,18 @@ import {
2526 QRCodeInterface ,
2627 QRCodeType ,
2728 QRCodeSettings ,
29+ EncryptionService ,
30+ EncryptedPayload ,
31+ QRCodeDataSchema ,
32+ ExportAccountDataSchema
2833} from '../index' ;
2934
3035export class AccountQR extends QRCode implements QRCodeInterface {
3136 /**
3237 * Construct an Account QR Code out of the
3338 * nem2-sdk Account or PublicAccount instance.
34- *
35- * @param transaction {Transaction }
39+ *
40+ * @param account {Account }
3641 * @param networkType {NetworkType}
3742 * @param chainId {string}
3843 */
@@ -41,6 +46,11 @@ export class AccountQR extends QRCode implements QRCodeInterface {
4146 * @var {Account}
4247 */
4348 public readonly account : Account ,
49+ /**
50+ * The password for encryption
51+ * @var {Password}
52+ */
53+ public readonly password : Password ,
4454 /**
4555 * The network type.
4656 * @var {NetworkType}
@@ -55,21 +65,46 @@ export class AccountQR extends QRCode implements QRCodeInterface {
5565 }
5666
5767 /**
58- * The `toJSON()` method should return the JSON
59- * representation of the QR Code content .
68+ * Parse a JSON QR code content into a AccountQR
69+ * object .
6070 *
61- * @return {string }
71+ * @param json {string}
72+ * @param password {Password}
73+ * @return {AccountQR }
74+ * @throws {Error } On empty `json` given.
75+ * @throws {Error } On missing `type` field value.
76+ * @throws {Error } On unrecognized QR code `type` field value.
6277 */
63- public toJSON ( ) : string {
78+ static fromJSON (
79+ json : string ,
80+ password : Password
81+ ) : AccountQR {
6482
65- const jsonSchema = {
66- 'v' : 3 ,
67- 'type' : this . type ,
68- 'network_id' : this . networkType ,
69- 'chain_id' : this . chainId ,
70- 'data' : 'not implemented yet' ,
71- } ;
83+ // create the QRCode object from JSON
84+ return ExportAccountDataSchema . parse ( json , password ) ;
85+ }
86+
87+ /**
88+ * The `getTypeNumber()` method should return the
89+ * version number for QR codes of the underlying class.
90+ *
91+ * @see https://en.wikipedia.org/wiki/QR_code#Storage
92+ * @return {number }
93+ */
94+ public getTypeNumber ( ) : number {
95+ // Type version for ContactQR is Version 10
96+ // This type of QR can hold up to 174 bytes of data.
97+ return 20 ;
98+ }
7299
73- return JSON . stringify ( jsonSchema ) ;
100+ /**
101+ * The `getSchema()` method should return an instance
102+ * of a sub-class of QRCodeDataSchema which describes
103+ * the QR Code data.
104+ *
105+ * @return {QRCodeDataSchema }
106+ */
107+ public getSchema ( ) : QRCodeDataSchema {
108+ return new ExportAccountDataSchema ( ) ;
74109 }
75- }
110+ }
0 commit comments