Skip to content

Commit 8b36519

Browse files
authored
Merge pull request #8 from evias/export-account
Improvements on Library Structure, Classes and Unit Tests
2 parents 8803597 + 70354f7 commit 8b36519

32 files changed

Lines changed: 1688 additions & 199 deletions

CHANGELOG.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
# CHANGELOG
22

3-
## v0.1.0
3+
## v0.3.0
44

5-
- added qr-library.
6-
- generate QRcode by string.
7-
- generate image base64 string by string.
5+
- Added class `EncryptedPayload`
6+
- Added class `EncryptionService`
7+
- Added data schemas structure with `QRCodeDataSchema`
8+
- Added data schema `AddContactDataSchema`
9+
- Added data schema `ExportAccountDataSchema`
10+
- Added data schema `RequestCosignatureDataSchema` child of Transaction data schema
11+
- Added data schema `RequestTransactionDataSchema` child of Transaction data schema
12+
- Unit tests for AccountQR, ContactQR, TransactionQR, CosignatureQR
13+
- Modified QRCode.toJSON() logic to make use of `build()` method
14+
- Fixed `AccountQR` generation of encrypted private keys for accounts
15+
- Fixed `ContactQR` to also hold `name` information (optional)
16+
- Fixed QR Code `TypeNumber`: ContactQR uses type 10, AccountQR type 20, TransactionQR type 40.
17+
- Removed class `QRService`
18+
- Removed encryption from `QRService` in `AccountQR`
819

920
## v0.2.0
21+
1022
- added QRcode base class
1123
- added AccountQR Class
1224
- added ContactQR Class
1325
- added TransactionQR Class
14-
- added ObjectQR Class
26+
- added ObjectQR Class
27+
28+
## v0.1.0
29+
30+
- added qr-library.
31+
- generate QRcode by string.
32+
- generate image base64 string by string.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The produced Base64 encoded payload can be used to display the QR Code. An examp
6666

6767
Important versions listed below. Refer to the [Changelog](CHANGELOG.md) for a full history of the project.
6868

69+
- [0.3.0](CHANGELOG.md) - 2019-05-27
6970
- [0.2.0](CHANGELOG.md) - 2019-05-01
7071
- [0.1.0](CHANGELOG.md) - 2019-04-20
7172

index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,31 @@
1313
* See the License for the specific language governing permissions and
1414
*limitations under the License.
1515
*/
16+
17+
// enumerations / interfaces
1618
export { QRCodeType } from './src/QRCodeType';
1719
export { QRCodeSettings } from './src/QRCodeSettings';
1820
export { QRCodeInterface } from './src/QRCodeInterface';
1921
export { QRCode } from './src/QRCode';
22+
23+
// QR Code data schemas
24+
export { QRCodeDataSchema } from './src/QRCodeDataSchema';
25+
export { AddContactDataSchema } from './src/schemas/AddContactDataSchema';
26+
export { ExportAccountDataSchema } from './src/schemas/ExportAccountDataSchema';
27+
export { ExportObjectDataSchema } from './src/schemas/ExportObjectDataSchema';
28+
export { RequestTransactionDataSchema } from './src/schemas/RequestTransactionDataSchema';
29+
export { RequestCosignatureDataSchema } from './src/schemas/RequestCosignatureDataSchema';
30+
31+
// encryption
32+
export { EncryptedPayload } from './src/EncryptedPayload';
33+
export { EncryptionService } from './src/services/EncryptionService';
34+
35+
// specialized QR Code classes
2036
export { AccountQR } from './src/AccountQR';
2137
export { ContactQR } from './src/ContactQR';
2238
export { ObjectQR } from './src/ObjectQR';
2339
export { TransactionQR } from './src/TransactionQR';
40+
export { CosignatureQR } from './src/CosignatureQR';
41+
42+
// factory
2443
export { QRCodeGenerator } from './src/QRCodeGenerator';

package-lock.json

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
"test": "test"
99
},
1010
"dependencies": {
11+
"crypto-js": "^3.1.9-1",
1112
"nem2-sdk": "^0.11.5",
1213
"qrcode-generator-ts": "^0.0.4"
1314
},
1415
"devDependencies": {
1516
"@types/chai": "^4.1.3",
1617
"@types/mocha": "^5.2.0",
18+
"@types/node": "^12.0.2",
1719
"chai": "^4.1.2",
1820
"coveralls": "^3.0.2",
1921
"mocha": "^5.2.0",

src/AccountQR.ts

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3035
export 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+
}

src/ContactQR.ts

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Account,
1818
PublicAccount,
1919
NetworkType,
20+
Address,
2021
} from "nem2-sdk";
2122

2223
// internal dependencies
@@ -25,20 +26,27 @@ import {
2526
QRCodeInterface,
2627
QRCodeType,
2728
QRCodeSettings,
29+
QRCodeDataSchema,
30+
AddContactDataSchema
2831
} from '../index';
2932

3033
export class ContactQR extends QRCode implements QRCodeInterface {
3134
/**
3235
* Construct a Contact QR Code out of the
3336
* nem2-sdk Account or PublicAccount instance.
34-
*
37+
*
3538
* @param account {Account|PublicAccount}
3639
* @param networkType {NetworkType}
3740
* @param chainId {string}
3841
*/
3942
constructor(/**
43+
* The contact name.
44+
* @var {string}
45+
*/
46+
public readonly name: string,
47+
/**
4048
* The contact account.
41-
* @var {Account|PublicAccount}
49+
* @var {Account|PublicAccount|Address}
4250
*/
4351
public readonly account: Account | PublicAccount,
4452
/**
@@ -55,21 +63,44 @@ export class ContactQR extends QRCode implements QRCodeInterface {
5563
}
5664

5765
/**
58-
* The `toJSON()` method should return the JSON
59-
* representation of the QR Code content.
66+
* Parse a JSON QR code content into a ContactQR
67+
* object.
6068
*
61-
* @return {string}
69+
* @param json {string}
70+
* @return {ContactQR}
71+
* @throws {Error} On empty `json` given.
72+
* @throws {Error} On missing `type` field value.
73+
* @throws {Error} On unrecognized QR code `type` field value.
6274
*/
63-
public toJSON(): string {
75+
static fromJSON(
76+
json: string
77+
): ContactQR {
6478

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-
};
79+
// create the QRCode object from JSON
80+
return AddContactDataSchema.parse(json);
81+
}
7282

73-
return JSON.stringify(jsonSchema);
83+
/**
84+
* The `getTypeNumber()` method should return the
85+
* version number for QR codes of the underlying class.
86+
*
87+
* @see https://en.wikipedia.org/wiki/QR_code#Storage
88+
* @return {number}
89+
*/
90+
public getTypeNumber(): number {
91+
// Type version for ContactQR is Version 10
92+
// This type of QR can hold up to 174 bytes of data.
93+
return 10;
94+
}
95+
96+
/**
97+
* The `getSchema()` method should return an instance
98+
* of a sub-class of QRCodeDataSchema which describes
99+
* the QR Code data.
100+
*
101+
* @return {QRCodeDataSchema}
102+
*/
103+
public getSchema(): QRCodeDataSchema {
104+
return new AddContactDataSchema();
74105
}
75-
}
106+
}

0 commit comments

Comments
 (0)