Skip to content

Commit

Permalink
Merge branch 'release/v1.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Winkler committed Sep 19, 2018
2 parents 1b579fd + bc5a28c commit 984b26c
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 41 deletions.
5 changes: 5 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
### Fixes
### Deprecations

## Version 1.2.1
### Fixes
- replace `interruptStep = 200` with `interruptStep = 2000` to fix old / mobile browser breaking by calling to many setTimeouts
- add `AesBlob` to index export and runtime

## Version 1.2.0
### Features
- add `NameResolver` class, that extends DBCPs version with `claimAddress` that allows to claim domains from a fifs registrar node
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@
"testunitbrk": "env-cmd ./.env.local npm run build && mocha --inspect-brk -r ts-node/register $*"
},
"types": "./dist/index.d.ts",
"version": "1.2.0"
}
"version": "1.2.1"
}
1 change: 1 addition & 0 deletions scripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const browserifyFile = async function(bundleName) {
.pipe(gulpReplace('exports.randomBytes = /* common-shake removed: exports.rng = */ void 0, /* common-shake removed: exports.pseudoRandomBytes = */ void 0, /* common-shake removed: exports.prng = */ require(\'randombytes\');', 'exports.randomBytes = require(\'randombytes\');'))
.pipe(gulpReplace('require("babel-polyfill");', ''))
.pipe(gulpReplace('var createBC = function () {', 'require("babel-polyfill");\nvar createBC = function () {'))
.pipe(gulpReplace('interruptStep\ \=\ 200\;', 'interruptStep\ \=\ 2000\;'))
.pipe(gulp.dest(`${bundleFolder}`))
.on('end', () => resolve())
)
Expand Down
10 changes: 6 additions & 4 deletions src/bundles/bcc/dbcp.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"files": [
"bcc.js"
],
"origin": "QmaAPp1kDch1NBZGja2MLDvcyFM2FPosd3U5YGofMWeG6q",
"origin": "QmXko1HcW2fzscqPfPbvtCoqWrCcvf73LKadW4jrdU1BMD",
"type": "library"
},
"description": "Contractus for loading ens entries and it's data...",
Expand All @@ -19,15 +19,17 @@
"contractus",
"library"
],
"version": "1.2.0",
"version": "1.2.1",
"versions": {
"0.1.0": "QmTsY7ASbvxATLnEemHZQ8oQha64ujYe9VXbDCouDk7Xtp",
"0.9.0": "Qmbw3yX82TVN9WhsRyeaRpd89M9XXL1pds9GgqJL29ohar",
"1.0.0": "QmcECAYTqmKP5AQwkKaCiov77KhgpNLTawAN3tmBCHQeTi",
"1.0.1": "QmQNVUFewk95FFkuA62E2TVZNV9w3L6ybMK3b82wyJpg25",
"1.0.2": "QmdC3NTNRPCs2VTrEQx1RNL6LoaDzhQLpa4nsAMA61sM7i",
"1.1.0": "QmeXw3ytsm7WWH71R1LEG1ocLbrVnGMzVLk4Wfx7FqQr6v",
"1.2.0": "QmPUppHfJh9FEcqYQJpYXWHtxSQsJfy1gwqhSCPGXccEpP"
}
"1.2.0": "QmSqC4ZP3yAncMKB31KBx6UqBzcxUg1wK4vT6Ku6dsQcBH",
"1.2.1": "QmZ9icmpYrWsUfdywcvmsa6M4nYRtN21PG2WYBwW1tqiXy"
},
"dbcpVersion": 1
}
}
8 changes: 2 additions & 6 deletions src/contracts/data-contract/data-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,6 @@ export class DataContract extends BaseContract {
if (!dfsStorage) {
return hash;
} else {
let hash = entryRaw;
if (encryptedHashes) {
hash = await this.decryptHash(entryRaw, dataContract, accountId);
}
const encryptedContent = (await this.options.dfs.get(hash)).toString('utf-8');
const decrypted = await this.decrypt(
encryptedContent,
Expand Down Expand Up @@ -645,7 +641,7 @@ export class DataContract extends BaseContract {
this.options.web3.eth.getBlockNumber(),
]);
await this.validate(description, entryName, value);
const encrypted = await this.encrypt({ private: value }, dataContract, accountId, entryName, blockNr, encryptionContext);
const encrypted = await this.encrypt({ private: value }, dataContract, accountId, entryName, blockNr);
const stateMd5 = crypto.createHash('md5').update(encrypted).digest('hex');
toSet = await this.options.dfs.add(stateMd5, Buffer.from(encrypted));
}
Expand Down Expand Up @@ -697,7 +693,7 @@ export class DataContract extends BaseContract {
this.options.web3.eth.getBlockNumber(),
]);
await this.validate(description, mappingName, value);
const encrypted = await this.encrypt({ private: value }, dataContract, accountId, mappingName, blockNr, encryptionContext);
const encrypted = await this.encrypt({ private: value }, dataContract, accountId, mappingName, blockNr);
const stateMd5 = crypto.createHash('md5').update(encrypted).digest('hex');
toSet = await this.options.dfs.add(stateMd5, Buffer.from(encrypted));
}
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/service-contract/service-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { Sharing } from '../sharing';

const requestWindowSize = 10;
const web3 = new Web3(null);
const uintMax = web3.utils.toBN('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
const uintMax = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";

const serviceSchema = {
type: 'object',
Expand Down
18 changes: 12 additions & 6 deletions src/encryption/aes-blob.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ import { TestUtils } from '../test/test-utils'

let sampleFile;
let fileDescription;
let fileValidation;
let ipfs;
const sampleEncryptedHex = '763e585420c5d1a4d46e2764ee4ff71e3019fb7dfabad91da1e5433171f8f87a37d1da127c50b91243901275f3df8815d1bd4a57401a62fa51fcb262962aefac3701594a6ed4fb0f006b618a02f6b9a4b8cfa83547a1884501170ae60ae7a1d4c7ae1899f64a70aeae65737e5b58a70193824d519f4ef963e922514eae4a9cb8c6ed3c48994fa006aa9323eecbdd1794';
const sampleKey = '346c22768f84f3050f5c94cec98349b3c5cbfa0b7315304e13647a49181fd1ef';
let encryptedFile;

describe('Blob Encryption', function() {
this.timeout(300000);
Expand All @@ -49,7 +50,12 @@ describe('Blob Encryption', function() {
name: 'testfile.spec.jpg',
fileType: 'image/jpeg',
file: sampleFile
};
};
fileValidation = {
name: 'testfile.spec.jpg',
fileType: 'image/jpeg',
file: sampleFile
};
ipfs = await TestUtils.getIpfs();
});

Expand All @@ -71,13 +77,13 @@ describe('Blob Encryption', function() {

it('should be able to encrypt a sample message', async () => {
const aes = new AesBlob({dfs: ipfs});
const encrypted = await aes.encrypt(fileDescription, { key: sampleKey, });
expect(encrypted.toString('hex')).to.deep.eq(sampleEncryptedHex);
encryptedFile = await aes.encrypt(fileDescription, { key: sampleKey, });
expect(encryptedFile.toString('hex')).not.to.be.undefined;
});

it('should be able to decrypt a sample message', async () => {
const aes = new AesBlob({dfs: ipfs});
const decrypted = await aes.decrypt(Buffer.from(sampleEncryptedHex, 'hex'), { key: sampleKey, });
expect(decrypted).to.deep.equal(fileDescription);
const decrypted = await aes.decrypt(Buffer.from(encryptedFile, 'hex'), { key: sampleKey, });
expect(decrypted).to.deep.equal(fileValidation);
});
});
40 changes: 20 additions & 20 deletions src/encryption/aes-blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ export class AesBlob extends Logger implements Cryptor {
const key = await (<any>global).crypto.subtle.importKey(
'raw',
decryptKey,
{
{
name: algorithm,
length: 256,
length: 256,
},
false,
['decrypt']
Expand All @@ -157,9 +157,9 @@ export class AesBlob extends Logger implements Cryptor {
const key = await (<any>global).crypto.subtle.importKey(
'raw',
encryptionKey,
{
{
name: algorithm,
length: 256,
length: 256,
},
false,
['encrypt']
Expand All @@ -173,7 +173,7 @@ export class AesBlob extends Logger implements Cryptor {
buffer
);
return Buffer.from(encrypted);
}
}

/**
* encrypt a message
Expand All @@ -189,12 +189,12 @@ export class AesBlob extends Logger implements Cryptor {
}
let encryptedWrapperMessage;
// its an array of blobs
if(Array.isArray(message)) {
if (Array.isArray(message)) {
const files = [];
for(let blob of message) {
for (let blob of message) {
let encrypted;
const initialVector = generateInitialVector();
if((<any>global).crypto.subtle) {
if ((<any>global).crypto && (<any>global).crypto.subtle) {
encrypted = await this.encryptBrowser(this.webCryptoAlgo, Buffer.from(blob.file), new Buffer(options.key, 'hex'), initialVector);
} else {
const cipher = crypto.createCipheriv(this.algorithm, new Buffer(options.key, 'hex'), initialVector);
Expand All @@ -208,14 +208,14 @@ export class AesBlob extends Logger implements Cryptor {
});
}
const hashes = await this.options.dfs.addMultiple(files);
for(var i=0; i < message.length; i++) {
for (var i=0; i < message.length; i++) {
message[i].file = hashes[i];
}
} else {
const initialVector = generateInitialVector();
const cipher = crypto.createCipheriv(this.algorithm, new Buffer(options.key, 'hex'), initialVector);
let encrypted;
if((<any>global).crypto.subtle) {
if ((<any>global).crypto && (<any>global).crypto.subtle) {
encrypted = await this.encryptBrowser(this.webCryptoAlgo,Buffer.from(message.file), new Buffer(options.key, 'hex'), initialVector);
} else {
const cipher = crypto.createCipheriv(this.algorithm, new Buffer(options.key, 'hex'), initialVector);
Expand All @@ -228,14 +228,14 @@ export class AesBlob extends Logger implements Cryptor {
}
const initialVector = generateInitialVector();
const wrapperMessage = Buffer.from(JSON.stringify(message), this.encodingUnencrypted);
if((<any>global).crypto.subtle) {
if ((<any>global).crypto && (<any>global).crypto.subtle) {
encryptedWrapperMessage = await this.encryptBrowser(this.webCryptoAlgo, Buffer.from(wrapperMessage), new Buffer(options.key, 'hex'), initialVector);
} else {
const wrapperDecipher = crypto.createCipheriv(this.algorithm, new Buffer(options.key, 'hex'), initialVector);
encryptedWrapperMessage = Buffer.concat([wrapperDecipher.update(wrapperMessage), wrapperDecipher.final()]);
}
return Promise.resolve(Buffer.concat([initialVector, encryptedWrapperMessage]));
} catch(ex) {
} catch (ex) {
this.log(`could not encrypt; ${ex.message || ex}`, 'error');
return Promise.reject(ex);
}
Expand All @@ -257,7 +257,7 @@ export class AesBlob extends Logger implements Cryptor {
const initialVector = message.slice(0, 16);
const encrypted = message.slice(16);
let decrypted;
if((<any>global).crypto.subtle) {
if ((<any>global).crypto && (<any>global).crypto.subtle) {
decrypted = await this.decryptBrowser(this.webCryptoAlgo, encrypted, new Buffer(options.key, 'hex'), initialVector);
} else {
const decipher = crypto.createDecipheriv(this.algorithm, new Buffer(options.key, 'hex'), initialVector);
Expand All @@ -267,19 +267,19 @@ export class AesBlob extends Logger implements Cryptor {
const wrapper = JSON.parse(decrypted.toString(this.encodingUnencrypted));


if(Array.isArray(wrapper)) {
if (Array.isArray(wrapper)) {
const encryptedFiles = [];
for(let blob of wrapper) {
for (let blob of wrapper) {
const ipfsFile = await this.options.dfs.get(blob.file, true);
let file = new Buffer('');
const initialVectorFile = ipfsFile.slice(0, 16);
const encryptedFile = ipfsFile.slice(16);
if((<any>global).crypto.subtle) {
if ((<any>global).crypto.subtle) {
file = await this.decryptBrowser(this.webCryptoAlgo, encryptedFile, new Buffer(options.key, 'hex'), initialVectorFile);
} else {
const fileDecipher = crypto.createDecipheriv(this.algorithm, new Buffer(options.key, 'hex'), initialVectorFile);
const chunks = this.chunkBuffer(encryptedFile, 1024);
for(let chunk of chunks) {
for (let chunk of chunks) {
file = Buffer.concat([file, fileDecipher.update(chunk)]);
}
file = Buffer.concat([file, fileDecipher.final()]);
Expand All @@ -291,12 +291,12 @@ export class AesBlob extends Logger implements Cryptor {
const initialVectorFile = ipfsFile.slice(0, 16);
const encryptedFile = ipfsFile.slice(16);
let file = new Buffer('');
if((<any>global).crypto.subtle) {
if ((<any>global).crypto && (<any>global).crypto.subtle) {
file = await this.decryptBrowser(this.webCryptoAlgo, encryptedFile, new Buffer(options.key, 'hex'), initialVectorFile);
} else {
const fileDecipher = crypto.createDecipheriv(this.algorithm, new Buffer(options.key, 'hex'), initialVectorFile);
const chunks = this.chunkBuffer(encryptedFile, 1024);
for(let chunk of chunks) {
for (let chunk of chunks) {
file = Buffer.concat([file, fileDecipher.update(chunk)]);
}
file = Buffer.concat([file, fileDecipher.final()]);
Expand All @@ -310,4 +310,4 @@ export class AesBlob extends Logger implements Cryptor {
return Promise.reject(ex);
}
}
}
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export {
} from '@evan.network/dbcp'

export { Aes } from './encryption/aes';
export { AesBlob } from './encryption/aes-blob';
export { AesEcb } from './encryption/aes-ecb';
export { ContractState } from './contracts/base-contract/base-contract';
export { createDefaultRuntime, Runtime } from './runtime';
Expand All @@ -49,5 +50,5 @@ export { Ipld } from './dfs/ipld';
export { KeyExchange } from './keyExchange';
export { Mailbox } from './mailbox';
export { Profile } from './profile/profile';
export { Sharing } from './contracts/sharing';
export { RightsAndRoles, ModificationType, PropertyType } from './contracts/rights-and-roles';
export { Sharing } from './contracts/sharing';
6 changes: 5 additions & 1 deletion src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
} from '@evan.network/dbcp';

import { Aes } from './encryption/aes';
import { AesBlob } from './encryption/aes-blob';
import { AesEcb } from './encryption/aes-ecb';
import { BaseContract } from './contracts/base-contract/base-contract';
import { config } from './config';
Expand Down Expand Up @@ -101,7 +102,9 @@ export async function createDefaultRuntime(web3: any, dfs: DfsInterface, runtime
// get/compile smart contracts
// It is possible to load contracts from non-default locations
const solcCfg = { compileContracts: false, }
if (runtimeConfig.contractsLoadPath) solcCfg['destinationPath'] = runtimeConfig.contractsLoadPath
if (runtimeConfig.contractsLoadPath) {
solcCfg['destinationPath'] = runtimeConfig.contractsLoadPath;
}
const solc = new smartContract.Solc({ config: solcCfg, log, });
await solc.ensureCompiled(runtimeConfig.additionalContractsPaths || [], solcCfg['destinationPath']);
const contracts = solc.getContracts();
Expand Down Expand Up @@ -131,6 +134,7 @@ export async function createDefaultRuntime(web3: any, dfs: DfsInterface, runtime
const cryptoConfig = {};
cryptoConfig['aes'] = new Aes();
cryptoConfig['unencrypted'] = new Unencrypted();
cryptoConfig['aesBlob'] = new AesBlob();
cryptoConfig['aesEcb'] = new AesEcb();
const cryptoProvider = new CryptoProvider(cryptoConfig);
const keyProvider = new KeyProvider({ keys: runtimeConfig.keyConfig, });
Expand Down

0 comments on commit 984b26c

Please sign in to comment.