Skip to content

Commit

Permalink
Merge pull request #8 from evias/export-account
Browse files Browse the repository at this point in the history
Improvements on Library Structure, Classes and Unit Tests
  • Loading branch information
AnthonyLaw authored May 28, 2019
2 parents 8803597 + 70354f7 commit 8b36519
Show file tree
Hide file tree
Showing 32 changed files with 1,688 additions and 199 deletions.
28 changes: 23 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
# CHANGELOG

## v0.1.0
## v0.3.0

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

## v0.2.0

- added QRcode base class
- added AccountQR Class
- added ContactQR Class
- added TransactionQR Class
- added ObjectQR Class
- added ObjectQR Class

## v0.1.0

- added qr-library.
- generate QRcode by string.
- generate image base64 string by string.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The produced Base64 encoded payload can be used to display the QR Code. An examp

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

- [0.3.0](CHANGELOG.md) - 2019-05-27
- [0.2.0](CHANGELOG.md) - 2019-05-01
- [0.1.0](CHANGELOG.md) - 2019-04-20

Expand Down
19 changes: 19 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,31 @@
* See the License for the specific language governing permissions and
*limitations under the License.
*/

// enumerations / interfaces
export { QRCodeType } from './src/QRCodeType';
export { QRCodeSettings } from './src/QRCodeSettings';
export { QRCodeInterface } from './src/QRCodeInterface';
export { QRCode } from './src/QRCode';

// QR Code data schemas
export { QRCodeDataSchema } from './src/QRCodeDataSchema';
export { AddContactDataSchema } from './src/schemas/AddContactDataSchema';
export { ExportAccountDataSchema } from './src/schemas/ExportAccountDataSchema';
export { ExportObjectDataSchema } from './src/schemas/ExportObjectDataSchema';
export { RequestTransactionDataSchema } from './src/schemas/RequestTransactionDataSchema';
export { RequestCosignatureDataSchema } from './src/schemas/RequestCosignatureDataSchema';

// encryption
export { EncryptedPayload } from './src/EncryptedPayload';
export { EncryptionService } from './src/services/EncryptionService';

// specialized QR Code classes
export { AccountQR } from './src/AccountQR';
export { ContactQR } from './src/ContactQR';
export { ObjectQR } from './src/ObjectQR';
export { TransactionQR } from './src/TransactionQR';
export { CosignatureQR } from './src/CosignatureQR';

// factory
export { QRCodeGenerator } from './src/QRCodeGenerator';
10 changes: 8 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"test": "test"
},
"dependencies": {
"crypto-js": "^3.1.9-1",
"nem2-sdk": "^0.11.5",
"qrcode-generator-ts": "^0.0.4"
},
"devDependencies": {
"@types/chai": "^4.1.3",
"@types/mocha": "^5.2.0",
"@types/node": "^12.0.2",
"chai": "^4.1.2",
"coveralls": "^3.0.2",
"mocha": "^5.2.0",
Expand Down
65 changes: 50 additions & 15 deletions src/AccountQR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
Account,
PublicAccount,
NetworkType,
Password,
} from "nem2-sdk";

// internal dependencies
Expand All @@ -25,14 +26,18 @@ import {
QRCodeInterface,
QRCodeType,
QRCodeSettings,
EncryptionService,
EncryptedPayload,
QRCodeDataSchema,
ExportAccountDataSchema
} from '../index';

export class AccountQR extends QRCode implements QRCodeInterface {
/**
* Construct an Account QR Code out of the
* nem2-sdk Account or PublicAccount instance.
*
* @param transaction {Transaction}
*
* @param account {Account}
* @param networkType {NetworkType}
* @param chainId {string}
*/
Expand All @@ -41,6 +46,11 @@ export class AccountQR extends QRCode implements QRCodeInterface {
* @var {Account}
*/
public readonly account: Account,
/**
* The password for encryption
* @var {Password}
*/
public readonly password: Password,
/**
* The network type.
* @var {NetworkType}
Expand All @@ -55,21 +65,46 @@ export class AccountQR extends QRCode implements QRCodeInterface {
}

/**
* The `toJSON()` method should return the JSON
* representation of the QR Code content.
* Parse a JSON QR code content into a AccountQR
* object.
*
* @return {string}
* @param json {string}
* @param password {Password}
* @return {AccountQR}
* @throws {Error} On empty `json` given.
* @throws {Error} On missing `type` field value.
* @throws {Error} On unrecognized QR code `type` field value.
*/
public toJSON(): string {
static fromJSON(
json: string,
password: Password
): AccountQR {

const jsonSchema = {
'v': 3,
'type': this.type,
'network_id': this.networkType,
'chain_id': this.chainId,
'data': 'not implemented yet',
};
// create the QRCode object from JSON
return ExportAccountDataSchema.parse(json, password);
}

/**
* The `getTypeNumber()` method should return the
* version number for QR codes of the underlying class.
*
* @see https://en.wikipedia.org/wiki/QR_code#Storage
* @return {number}
*/
public getTypeNumber(): number {
// Type version for ContactQR is Version 10
// This type of QR can hold up to 174 bytes of data.
return 20;
}

return JSON.stringify(jsonSchema);
/**
* The `getSchema()` method should return an instance
* of a sub-class of QRCodeDataSchema which describes
* the QR Code data.
*
* @return {QRCodeDataSchema}
*/
public getSchema(): QRCodeDataSchema {
return new ExportAccountDataSchema();
}
}
}
61 changes: 46 additions & 15 deletions src/ContactQR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
Account,
PublicAccount,
NetworkType,
Address,
} from "nem2-sdk";

// internal dependencies
Expand All @@ -25,20 +26,27 @@ import {
QRCodeInterface,
QRCodeType,
QRCodeSettings,
QRCodeDataSchema,
AddContactDataSchema
} from '../index';

export class ContactQR extends QRCode implements QRCodeInterface {
/**
* Construct a Contact QR Code out of the
* nem2-sdk Account or PublicAccount instance.
*
*
* @param account {Account|PublicAccount}
* @param networkType {NetworkType}
* @param chainId {string}
*/
constructor(/**
* The contact name.
* @var {string}
*/
public readonly name: string,
/**
* The contact account.
* @var {Account|PublicAccount}
* @var {Account|PublicAccount|Address}
*/
public readonly account: Account | PublicAccount,
/**
Expand All @@ -55,21 +63,44 @@ export class ContactQR extends QRCode implements QRCodeInterface {
}

/**
* The `toJSON()` method should return the JSON
* representation of the QR Code content.
* Parse a JSON QR code content into a ContactQR
* object.
*
* @return {string}
* @param json {string}
* @return {ContactQR}
* @throws {Error} On empty `json` given.
* @throws {Error} On missing `type` field value.
* @throws {Error} On unrecognized QR code `type` field value.
*/
public toJSON(): string {
static fromJSON(
json: string
): ContactQR {

const jsonSchema = {
'v': 3,
'type': this.type,
'network_id': this.networkType,
'chain_id': this.chainId,
'data': 'not implemented yet',
};
// create the QRCode object from JSON
return AddContactDataSchema.parse(json);
}

return JSON.stringify(jsonSchema);
/**
* The `getTypeNumber()` method should return the
* version number for QR codes of the underlying class.
*
* @see https://en.wikipedia.org/wiki/QR_code#Storage
* @return {number}
*/
public getTypeNumber(): number {
// Type version for ContactQR is Version 10
// This type of QR can hold up to 174 bytes of data.
return 10;
}

/**
* The `getSchema()` method should return an instance
* of a sub-class of QRCodeDataSchema which describes
* the QR Code data.
*
* @return {QRCodeDataSchema}
*/
public getSchema(): QRCodeDataSchema {
return new AddContactDataSchema();
}
}
}
Loading

0 comments on commit 8b36519

Please sign in to comment.