-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
107 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
|
||
}) | ||
}) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ | |
true, | ||
"double", | ||
"avoid-escape" | ||
], | ||
"semicolon": [ | ||
true, | ||
"always" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters