Skip to content

New Catbuffer sanity check (DON'T MERGE) #807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
extends: [
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'prettier', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
parserOptions: {
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ Licensed under the [Apache License 2.0](LICENSE)
[sdk-ref]: https://nemtech.github.io/references/typescript-sdk.html
[guidelines]: https://nemtech.github.io/contribute/contributing.html#sdk
[slack]: https://join.slack.com/t/nem2/shared_invite/enQtMzY4MDc2NTg0ODgyLWZmZWRiMjViYTVhZjEzOTA0MzUyMTA1NTA5OWQ0MWUzNTA4NjM5OTJhOGViOTBhNjkxYWVhMWRiZDRkOTE0YmU


// "catbuffer-typescript": "file://~/develop/workspace-nem/catbuffer-generators/build/typescript/catbuffer-typescript",
6 changes: 2 additions & 4 deletions e2e/infrastructure/BlockHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ describe('BlockHttp', () => {
describe('getBlockByHeight', () => {
it('should return block info given height', async () => {
const blockInfo = await blockRepository.getBlockByHeight(UInt64.fromUint(1)).toPromise();
expect(blockInfo.height.lower).to.be.equal(1);
expect(blockInfo.height.higher).to.be.equal(0);
expect(blockInfo.timestamp.lower).to.be.equal(0);
expect(blockInfo.timestamp.higher).to.be.equal(0);
expect(blockInfo.height.value).to.be.equal(BigInt(1));
expect(blockInfo.timestamp.value).to.be.equal(BigInt(0));
expect(blockInfo.beneficiaryAddress).not.to.be.undefined;
expect(blockInfo.statementsCount).not.to.be.undefined;
});
Expand Down
3 changes: 1 addition & 2 deletions e2e/infrastructure/ChainHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ describe('ChainHttp', () => {
it('should return blockchain score', async () => {
const info = await chainRepository.getChainInfo().toPromise();
expect(info.scoreLow).to.not.be.equal(undefined);
expect(info.scoreHigh.lower).to.be.equal(0);
expect(info.scoreHigh.higher).to.be.equal(0);
expect(info.scoreHigh.value).to.be.equal(0);
});
});
});
4 changes: 2 additions & 2 deletions e2e/infrastructure/IntegrationTestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export class IntegrationTestHelper {
public static sleep(ms: number): Promise<any> {
// Create a promise that rejects in <ms> milliseconds
return new Promise((resolve) => {
setTimeout(() => {
resolve();
setTimeout((): void => {
resolve(undefined);
}, ms);
});
}
Expand Down
11,163 changes: 10,765 additions & 398 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"e2e": "npm run bootstrap-stop && npm run bootstrap-start-detached && npm run test:e2e && npm run bootstrap-stop",
"test:all": "mocha --ui bdd --recursive ./dist/ --timeout 90000 --unhandled-rejections=strict",
"build": "shx rm -rf dist/ && tsc && npm run e2econfigcopy",
"watch": "tsc -w",
"test:cov": "nyc --reporter=lcov --reporter=text-summary npm t",
"test:coveralls": "npm run test:cov | coveralls",
"coveralls-report": "cat ./coverage/lcov.info | coveralls",
Expand Down Expand Up @@ -65,6 +66,7 @@
"@types/lodash": "^4.14.161",
"@types/long": "^4.0.1",
"@types/mocha": "^2.2.48",
"@types/node": "^12.12.6",
"@types/ripemd160": "^2.0.0",
"@types/utf8": "^2.1.6",
"@types/ws": "^3.2.1",
Expand All @@ -90,15 +92,15 @@
"shx": "^0.3.2",
"symbol-bootstrap": "^0.4.3",
"ts-mockito": "^2.6.1",
"ts-node": "^8.10.2",
"ts-node": "^10.1.0",
"typedoc": "^0.20.36",
"typescript": "^3.9.7",
"typescript-require": "^0.2.10"
},
"dependencies": {
"@js-joda/core": "^3.2.0",
"bluebird": "^3.7.2",
"catbuffer-typescript": "0.1.1",
"catbuffer-typescript": "^1.0.1-alpha-202107291344",
"crypto-js": "^4.0.0",
"diff": "^4.0.2",
"futoin-hkdf": "^1.3.2",
Expand Down
7 changes: 4 additions & 3 deletions src/core/crypto/Crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import * as crypto from 'crypto';
import { CipherCCM, DecipherCCM } from 'crypto';
import * as CryptoJS from 'crypto-js';
import { Convert as convert } from '../format/Convert';
import { KeyPair } from './KeyPair';
Expand Down Expand Up @@ -96,7 +97,7 @@ export class Crypto {
const keyPair = KeyPair.createKeyPairFromPrivateKeyString(senderPriv);
const encKey = Buffer.from(utility.catapult_crypto.deriveSharedKey(keyPair.privateKey, convert.hexToUint8(recipientPub)), 32);
const encIv = Buffer.from(iv);
const cipher = crypto.createCipheriv(Crypto.AES_ALGO, encKey, encIv);
const cipher = crypto.createCipheriv(Crypto.AES_ALGO, encKey, encIv) as CipherCCM;
const encrypted = Buffer.concat([cipher.update(Buffer.from(convert.hexToUint8(msg))), cipher.final()]);
const tag = cipher.getAuthTag();
// Result
Expand Down Expand Up @@ -144,7 +145,7 @@ export class Crypto {
const encKey = Buffer.from(utility.catapult_crypto.deriveSharedKey(keyPair.privateKey, convert.hexToUint8(senderPublic)), 32);
const encIv = Buffer.from(new Uint8Array(tagAndIv.buffer, 16, 12));
const encTag = Buffer.from(new Uint8Array(tagAndIv.buffer, 0, 16));
const cipher = crypto.createDecipheriv(Crypto.AES_ALGO, encKey, encIv);
const cipher = crypto.createDecipheriv(Crypto.AES_ALGO, encKey, encIv) as DecipherCCM;
cipher.setAuthTag(encTag);
const decrypted = Buffer.concat([cipher.update(Buffer.from(payload)), cipher.final()]);
// Result
Expand Down Expand Up @@ -183,7 +184,7 @@ export class Crypto {
*
* @return {Uint8Array}
*/
public static randomBytes = (length: number): any => {
public static randomBytes = (length: number): Buffer => {
return crypto.randomBytes(length);
};
}
4 changes: 1 addition & 3 deletions src/core/crypto/KeyPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export class KeyPair {
* @param {string} privateKeyString A hex encoded private key string.
* @returns {module:crypto/keyPair~KeyPair} The key pair.
*/
public static createKeyPairFromPrivateKeyString(
privateKeyString: string,
): {
public static createKeyPairFromPrivateKeyString(privateKeyString: string): {
privateKey: Uint8Array;
publicKey: Uint8Array;
} {
Expand Down
119 changes: 7 additions & 112 deletions src/core/crypto/nacl_catapult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,128 +42,23 @@ const gf0 = gf(),
gf1 = gf([1]),
_121665 = gf([0xdb41, 1]),
D = gf([
0x78a3,
0x1359,
0x4dca,
0x75eb,
0xd8ab,
0x4141,
0x0a4d,
0x0070,
0xe898,
0x7779,
0x4079,
0x8cc7,
0xfe73,
0x2b6f,
0x6cee,
0x5203,
0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203,
]),
D2 = gf([
0xf159,
0x26b2,
0x9b94,
0xebd6,
0xb156,
0x8283,
0x149a,
0x00e0,
0xd130,
0xeef3,
0x80f2,
0x198e,
0xfce7,
0x56df,
0xd9dc,
0x2406,
0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406,
]),
X = gf([
0xd51a,
0x8f25,
0x2d60,
0xc956,
0xa7b2,
0x9525,
0xc760,
0x692c,
0xdc5c,
0xfdd6,
0xe231,
0xc0a4,
0x53fe,
0xcd6e,
0x36d3,
0x2169,
0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169,
]),
Y = gf([
0x6658,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6666,
0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666,
]),
I = gf([
0xa0b0,
0x4a0e,
0x1b27,
0xc4ee,
0xe478,
0xad2f,
0x1806,
0x2f43,
0xd7a7,
0x3dfb,
0x0099,
0x2b4d,
0xdf0b,
0x4fc1,
0x2480,
0x2b83,
0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83,
]);
const L = new Float64Array([
0xed,
0xd3,
0xf5,
0x5c,
0x1a,
0x63,
0x12,
0x58,
0xd6,
0x9c,
0xf7,
0xa2,
0xde,
0xf9,
0xde,
0x14,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0x10,
0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0x10,
]);

const A = (o, a, b) => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/format/IdGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class IdGenerator {
* @param {string} name The unified namespace name.
* @returns {array<module:coders/uint64~uint64>} The namespace path.
*/
public static generateNamespacePath = (name: string): number[] => {
public static generateNamespacePath = (name: string): number[][] => {
if (0 >= name.length) {
utilities.throwInvalidFqn('having zero length', name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/format/KeyGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export class KeyGenerator {
}
const buf = sha3_256.arrayBuffer(input);
const result = new Uint32Array(buf);
return new UInt64([result[0], (result[1] | 0x80000000) >>> 0]);
return UInt64.fromNumberArray([result[0], (result[1] | 0x80000000) >>> 0]);
}
}
2 changes: 1 addition & 1 deletion src/core/utils/DtoMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class DtoMapping {
* @param value enum value to be mapped
*/
public static mapEnum<E1, E2>(value: E1 | undefined): E2 {
return (value as unknown) as E2;
return value as unknown as E2;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/infrastructure/transaction/NamespaceMosaicIdGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ export class NamespaceMosaicIdGenerator {
/**
* @returns random mosaic nonce
*/
public static generateRandomMosaicNonce = (): any => {
public static generateRandomMosaicNonce = (): Buffer => {
return Crypto.randomBytes(4);
};

/**
* @param {string} namespaceName - The namespace name
* @returns sub namespace id
*/
public static namespaceId = (namespaceName: string): any => {
public static namespaceId = (namespaceName: string): number[] => {
const path = IdGenerator.generateNamespacePath(namespaceName);
return path.length ? IdGenerator.generateNamespacePath(namespaceName)[path.length - 1] : [];
return path[path.length - 1];
};
/**
* @param {string} parentNamespaceName - The parent namespace name
* @param {string} namespaceName - The namespace name
* @returns sub namespace parent id
*/
public static subnamespaceParentId = (parentNamespaceName: string, namespaceName: string): any => {
public static subnamespaceParentId = (parentNamespaceName: string, namespaceName: string): number[] => {
const path = IdGenerator.generateNamespacePath(`${parentNamespaceName}.${namespaceName}`);
return IdGenerator.generateNamespacePath(parentNamespaceName)[path.length - 2];
};
Expand All @@ -57,7 +57,7 @@ export class NamespaceMosaicIdGenerator {
* @param {string} namespaceName - The namespace name
* @returns sub namespace id
*/
public static subnamespaceNamespaceId = (parentNamespaceName: string, namespaceName: string): any => {
public static subnamespaceNamespaceId = (parentNamespaceName: string, namespaceName: string): number[] => {
const path = IdGenerator.generateNamespacePath(`${parentNamespaceName}.${namespaceName}`);
return path[path.length - 1];
};
Expand Down
49 changes: 0 additions & 49 deletions src/model/Id.ts

This file was deleted.

Loading