Skip to content

Commit

Permalink
ci: Setup CircleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
theofilis committed Mar 19, 2017
1 parent 5ec21e3 commit ac8a5b1
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 95 deletions.
27 changes: 27 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 2

jobs:
build:
working_directory: ~/iroha-javascript
docker:
- image: node:7.7
steps:
- checkout
- restore_cache:
key: irohajs-{{ .Branch }}-{{ checksum "package.json" }}
- run:
name: Pre-Dependencies
command: mkdir ~/iroha-javascript/artifacts
- run:
name: Install Dependencies
command: npm prune && npm cache clean && npm install
- run:
name: Test & Build
command: npm run test:prod && npm run build
- store_artifacts:
path: ~/iroha-javascript/dist
destination: iroha
- save_cache:
key: irohajs-{{ .Branch }}-{{ checksum "package.json" }}
paths:
- "~/iroha-javascript/node_modules"
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"author": "",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/soramitsu/iroha-javascript/issues"
"url": "https://github.com/hyperledger/iroha-javascript/issues"
},
"homepage": "https://github.com/soramitsu/iroha-javascript#readme",
"homepage": "https://github.com/hyperledger/iroha-javascript#readme",
"engines": {
"node": ">=6.0.0"
},
Expand Down
50 changes: 25 additions & 25 deletions src/irohajs.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
const sha3_256 = require("js-sha3").sha3_256
const supercop = require("supercop.js")
const sha3_256 = require("js-sha3").sha3_256;
const supercop = require("supercop.js");

export function createKeyPair (): IKeyPair {
const seed = supercop.createSeed()
const keys = supercop.createKeyPair(seed)
const seed = supercop.createSeed();
const keys = supercop.createKeyPair(seed);

return {
publicKey: keys.publicKey.toString("base64"),
privateKey: keys.secretKey.toString("base64")
}
};
}

export function sign (opt: { publicKey: string, privateKey: string, message: string }): string {
const publicKey = new Buffer(opt.publicKey, "base64")
const privateKey = new Buffer(opt.privateKey, "base64")
const sha3Message = new Buffer(sha3_256(opt.message))
const publicKey = new Buffer(opt.publicKey, "base64");
const privateKey = new Buffer(opt.privateKey, "base64");
const sha3Message = new Buffer(sha3_256(opt.message));

const sig = supercop.sign(
sha3Message,
publicKey,
privateKey
).toString("base64")
).toString("base64");

return sig
return sig;
}

export function verify (opt: { publicKey: string, message: string, signature: string }) {
const valid = supercop.verify(
new Buffer(opt.signature, "base64"),
new Buffer(opt.message),
new Buffer(opt.publicKey, "base64")
)
return valid
);
return valid;
}

export interface IKeyPair {
privateKey: string
publicKey: string
privateKey: string;
publicKey: string;
}

export interface IWallet {
privateKey: Buffer
publicKey: Buffer
privateKey: Buffer;
publicKey: Buffer;
}

export class Wallet implements IWallet {
privateKey: Buffer
publicKey: Buffer
privateKey: Buffer;
publicKey: Buffer;

constructor (keyPair?: IWallet) {
const seed = supercop.createSeed()
const keys = keyPair || supercop.createKeyPair(seed)
const seed = supercop.createSeed();
const keys = keyPair || supercop.createKeyPair(seed);

this.publicKey = keys.publicKey
this.privateKey = (keyPair) ? keyPair.privateKey : keys.secretKey
this.publicKey = keys.publicKey;
this.privateKey = (keyPair) ? keyPair.privateKey : keys.secretKey;
}

toJSON (): IKeyPair {
return {
publicKey: this.publicKey.toString("base64"),
privateKey: this.privateKey.toString("base64")
}
};
}

sign (msg: string): string {
const message = new Buffer(sha3_256(msg))
return supercop.sign(message, this.publicKey, this.privateKey).toString("base64")
const message = new Buffer(sha3_256(msg));
return supercop.sign(message, this.publicKey, this.privateKey).toString("base64");
}
}
86 changes: 43 additions & 43 deletions test/irohajs.test.ts
Original file line number Diff line number Diff line change
@@ -1,95 +1,95 @@
import * as iroha from "../src/irohajs"
const sha3_256 = require("js-sha3").sha3_256
const supercop = require("supercop.js")
import * as iroha from "../src/irohajs";
const sha3_256 = require("js-sha3").sha3_256;
const supercop = require("supercop.js");

describe("TEST Iroha javascript", () => {
const publicKey = "qzesd0bqIFfx1RQDS2HgcG5DQq/7DYF8u1YfMHAeJUs="
const privateKey = "MEjhWDSSeQobXA55uYR+EFxEQOoQ68db59Gi1ocQ7ljWZNNQM35MJQpst83FcCKI1hra/53IxeZijEUIiM/Reg=="
const signature = "wg8rlcWHe+PjkmJDllfMIF4PYUEbvNJ/yaoTmWzQUFe3mjnvuXnG3UWwNJfn47ms670sMvELXcliugBBhgeoCA=="
const publicKey = "qzesd0bqIFfx1RQDS2HgcG5DQq/7DYF8u1YfMHAeJUs=";
const privateKey = "MEjhWDSSeQobXA55uYR+EFxEQOoQ68db59Gi1ocQ7ljWZNNQM35MJQpst83FcCKI1hra/53IxeZijEUIiM/Reg==";
const signature = "wg8rlcWHe+PjkmJDllfMIF4PYUEbvNJ/yaoTmWzQUFe3mjnvuXnG3UWwNJfn47ms670sMvELXcliugBBhgeoCA==";

beforeEach((done) => {
done()
})
done();
});

describe("Iroha Create new KeyPair", () => {
it("Create new KeyPair!", () => {
const keyPair = iroha.createKeyPair()
expect(keyPair).toBeDefined()
})
})
const keyPair = iroha.createKeyPair();
expect(keyPair).toBeDefined();
});
});

describe("Iroha Create new Wallet", () => {
it("Create new Wallet!", () => {
const wallet = new iroha.Wallet()
expect(wallet.toJSON()).toBeDefined()
})
const wallet = new iroha.Wallet();
expect(wallet.toJSON()).toBeDefined();
});

it("Create new Wallet!", () => {
const wallet = new iroha.Wallet({
privateKey: new Buffer(privateKey, "base64"),
publicKey: new Buffer(publicKey, "base64")
})
expect(wallet.privateKey.toString("base64")).toBe(privateKey)
expect(wallet.publicKey.toString("base64")).toBe(publicKey)
})
});
expect(wallet.privateKey.toString("base64")).toBe(privateKey);
expect(wallet.publicKey.toString("base64")).toBe(publicKey);
});

it("Check signature", () => {
const wallet = new iroha.Wallet({
privateKey: new Buffer(privateKey, "base64"),
publicKey: new Buffer(publicKey, "base64")
})
const sig = wallet.sign("test")
expect(sig).toBe(signature)
})
})
});
const sig = wallet.sign("test");
expect(sig).toBe(signature);
});
});

describe("Iroha CreateSignature", () => {
it("Signature succeeded!", () => {
const msg = "test"
const msg = "test";
const sig = iroha.sign({
"publicKey": publicKey,
"privateKey": privateKey,
"message": msg
})
});

expect(sig).toBe(signature)
})
expect(sig).toBe(signature);
});

it("Signature not succeeded!", () => {
const msg = "abcd"
const msg = "abcd";
const sig = iroha.sign({
"publicKey": publicKey,
"privateKey": privateKey,
"message": msg
})
});

expect(sig).not.toBe(signature)
})
expect(sig).not.toBe(signature);
});

})
});

describe("Iroha Verify", () => {
it("Verify succeeded!", () => {
const msg = sha3_256("test")
const msg = sha3_256("test");
const res = iroha.verify({
"publicKey": publicKey,
"message": msg,
"signature": signature
})
});

expect(res).toBeTruthy()
})
expect(res).toBeTruthy();
});

it("Verify not succeeded!", () => {
const msg = sha3_256("abcd")
const msg = sha3_256("abcd");
const res = iroha.verify({
"publicKey": publicKey,
"message": msg,
"signature": signature
})
});

expect(res).not.toBeTruthy()
})
expect(res).not.toBeTruthy();
});

})
})
});
});
4 changes: 4 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
true,
"double",
"avoid-escape"
],
"semicolon": [
true,
"always"
]
}
}
12 changes: 6 additions & 6 deletions webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { join } from "path"
const { camelCase } = require("lodash")
const { TsConfigPathsPlugin, CheckerPlugin } = require("awesome-typescript-loader")
const TypedocWebpackPlugin = require("typedoc-webpack-plugin")
import { join } from "path";
const { camelCase } = require("lodash");
const { TsConfigPathsPlugin, CheckerPlugin } = require("awesome-typescript-loader");
const TypedocWebpackPlugin = require("typedoc-webpack-plugin");

/**
* Update this variable if you change your library name
*/
const libraryName = "irohajs"
const libraryName = "irohajs";

export default {
entry: join(__dirname, `src/${libraryName}.ts`),
Expand Down Expand Up @@ -51,4 +51,4 @@ export default {
net: "empty",
tls: "empty"
}
}
};

0 comments on commit ac8a5b1

Please sign in to comment.