diff --git a/js-bindings/tests/PrivateKey.spec.js b/js-bindings/tests/PrivateKey.spec.js index 798069375..f1e778898 100644 --- a/js-bindings/tests/PrivateKey.spec.js +++ b/js-bindings/tests/PrivateKey.spec.js @@ -42,20 +42,12 @@ before((done) => { }); }); -function makehash(msg) { - return crypto - .createHash('sha256') - .update(msg) - .digest(); -} - describe('PrivateKey', () => { it('Should sign and verify', () => { - const {AugSchemeMPL, PrivateKey} = blsSignatures; + const {AugSchemeMPL} = blsSignatures; const message1 = Uint8Array.from([1, 65, 254, 88, 90, 45, 22]); - const seed = Uint8Array.from([28, 20, 102, 229, 1, 157]); const sk1 = AugSchemeMPL.key_gen(getPkSeed()); const pk1 = AugSchemeMPL.sk_to_g1(sk1); const sig1 = AugSchemeMPL.sign(sk1, message1); @@ -75,14 +67,14 @@ describe('PrivateKey', () => { describe('.fromBytes', () => { it('Should create a private key from a Buffer', () => { - const {PrivateKey, Util} = blsSignatures; + const {PrivateKey} = blsSignatures; const pk = PrivateKey.from_bytes(getPkBuffer(), false); assert(pk instanceof PrivateKey); assert.deepStrictEqual(pk.serialize(), getPkBuffer()); }); it('Should create a private key from a Uint8Array', () => { - const {PrivateKey, Util} = blsSignatures; + const {PrivateKey} = blsSignatures; const pk = PrivateKey.from_bytes(getPkUint8Array(), false); assert(pk instanceof PrivateKey); @@ -92,7 +84,7 @@ describe('PrivateKey', () => { describe('#serialize', () => { it('Should serialize key to a Buffer', () => { - const {AugSchemeMPL, PrivateKey} = blsSignatures; + const {AugSchemeMPL} = blsSignatures; const pk = AugSchemeMPL.key_gen(getPkSeed()); const serialized = pk.serialize(); @@ -117,7 +109,7 @@ describe('PrivateKey', () => { describe('#getPublicKey', () => { it('Should return a public key with a verifiable fingerprint', () => { - const {AugSchemeMPL, PrivateKey, G1Element} = blsSignatures; + const {AugSchemeMPL, G1Element} = blsSignatures; const pk = AugSchemeMPL.key_gen(getPkSeed()); const publicKey = AugSchemeMPL.sk_to_g1(pk); diff --git a/js-bindings/tests/PublicKey.spec.js b/js-bindings/tests/PublicKey.spec.js index 3effbbd98..9e21cc6e4 100644 --- a/js-bindings/tests/PublicKey.spec.js +++ b/js-bindings/tests/PublicKey.spec.js @@ -43,7 +43,7 @@ before((done) => { describe('G1Element', () => { describe('.from_bytes', () => { it('Should create a public key from bytes', () => { - const {G1Element, Util} = blsSignatures; + const {G1Element} = blsSignatures; const pk = G1Element.from_bytes(getPublicKeyFixture().buffer); assert(pk instanceof G1Element); diff --git a/js-bindings/tests/Signature.spec.js b/js-bindings/tests/Signature.spec.js index 555093bef..94b452e90 100644 --- a/js-bindings/tests/Signature.spec.js +++ b/js-bindings/tests/Signature.spec.js @@ -30,7 +30,7 @@ before((done) => { describe('Signature', () => { describe('Integration', () => { it('Should verify signatures', function () { - const {BasicSchemeMPL, G2Element, G1Element, PrivateKey} = blsSignatures; + const {BasicSchemeMPL} = blsSignatures; this.timeout(10000); const message = Uint8Array.from([100, 2, 254, 88, 90, 45, 23]); @@ -72,7 +72,7 @@ describe('Signature', () => { }); describe('.fromBytes', () => { it('Should create verifiable signature from bytes', () => { - const {AugSchemeMPL, G2Element, Util} = blsSignatures; + const {G2Element} = blsSignatures; const sig = G2Element.fromBytes(getSignatureBytes()); @@ -87,7 +87,7 @@ describe('Signature', () => { }); describe('.aggregateSigs', () => { it('Should aggregate signature', () => { - const {AugSchemeMPL, G2Element, PrivateKey} = blsSignatures; + const {AugSchemeMPL, G2Element} = blsSignatures; const sk = AugSchemeMPL.key_gen(makehash(Uint8Array.from([1, 2, 3]))); const pk = AugSchemeMPL.sk_to_g1(sk); @@ -107,7 +107,7 @@ describe('Signature', () => { }); describe('#serialize', () => { it('Should serialize signature to Buffer', () => { - const {AugSchemeMPL, G2Element, PrivateKey} = blsSignatures; + const {AugSchemeMPL, G2Element} = blsSignatures; const sk = AugSchemeMPL.key_gen(makehash(Uint8Array.from([1, 2, 3, 4, 5]))); const sig = AugSchemeMPL.sign(sk, Uint8Array.from([100, 2, 254, 88, 90, 45, 23])); @@ -120,7 +120,7 @@ describe('Signature', () => { }); describe('#verify', () => { it('Should return true if signature can be verified', () => { - const {AugSchemeMPL, G2Element, G1Element} = blsSignatures; + const {AugSchemeMPL} = blsSignatures; const message = Uint8Array.from(Buffer.from('Message')); const seed1 = makehash(Buffer.from([1, 2, 3, 4, 5])); @@ -144,7 +144,7 @@ describe('Signature', () => { sig.delete(); }); it("Should return false if signature can't be verified", () => { - const {AugSchemeMPL, G1Element, PrivateKey} = blsSignatures; + const {AugSchemeMPL} = blsSignatures; const message1 = Uint8Array.from(Buffer.from('Message')); const message2 = Uint8Array.from(Buffer.from('Nessage')); diff --git a/js-bindings/tests/karma.conf.js b/js-bindings/tests/karma.conf.js index cd5a2cb15..26fc7f32e 100644 --- a/js-bindings/tests/karma.conf.js +++ b/js-bindings/tests/karma.conf.js @@ -1,5 +1,4 @@ const testSource = './karma.test.js'; -const mime = require('mime'); const fs = require('fs'); function webpackConfig() { diff --git a/js-bindings/tests/test.js b/js-bindings/tests/test.js index 7444e82cc..e16e88c3d 100644 --- a/js-bindings/tests/test.js +++ b/js-bindings/tests/test.js @@ -45,7 +45,6 @@ blsjs().then((blsjs) => { G2Element, PopSchemeMPL, PrivateKey, - Util } = blsjs; function test_schemes() { @@ -155,7 +154,7 @@ blsjs().then((blsjs) => { invalid_inputs_1.map((s) => { const bytes_ = binascii.unhexlify(s); try { - const g1 = G1Element(bytes_); + G1Element(bytes_); console.log(`Failed to disallow creation of G1 element for string ${s}`); assert(false); } catch(e) { @@ -166,7 +165,7 @@ blsjs().then((blsjs) => { invalid_inputs_2.map((s) => { const bytes_ = binascii.unhexlify(s); try { - const g2 = G2Element(bytes_); + G2Element(bytes_); console.log(`Failed to disallow creation of G2 element for string ${s}`); assert(false); } catch(e) { @@ -361,7 +360,6 @@ blsjs().then((blsjs) => { const master_sk = AugSchemeMPL.key_gen(seed); const child = AugSchemeMPL.derive_child_sk(master_sk, 152); - const grandchild = AugSchemeMPL.derive_child_sk(child, 952); const master_pk = master_sk.get_g1(); const child_u = AugSchemeMPL.derive_child_sk_unhardened(master_sk, 22); @@ -387,15 +385,15 @@ blsjs().then((blsjs) => { console.log("\nAll tests passed."); }); -const copyright = [ - 'Copyright 2020 Chia Network Inc', - 'Licensed under the Apache License, Version 2.0 (the "License");', - 'you may not use this file except in compliance with the License.', - 'You may obtain a copy of the License at', - 'http://www.apache.org/licenses/LICENSE-2.0', - 'Unless required by applicable law or agreed to in writing, software', - 'distributed under the License is distributed on an "AS IS" BASIS,', - 'WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.', - 'See the License for the specific language governing permissions and', - 'limitations under the License.' -]; +/* + Copyright 2020 Chia Network Inc + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ diff --git a/js-bindings/tests/typings.spec.ts b/js-bindings/tests/typings.spec.ts index ba18efe48..dd77f0fdc 100644 --- a/js-bindings/tests/typings.spec.ts +++ b/js-bindings/tests/typings.spec.ts @@ -1,7 +1,6 @@ // This file is used to check if the typescript typings are working import createBlsSignaturesModule from '..'; -import {deepStrictEqual, ok, strictEqual} from 'assert'; -import {createHash} from 'crypto'; +import {ok, strictEqual} from 'assert'; createBlsSignaturesModule().then((blsSignatures) => { const { @@ -11,10 +10,6 @@ createBlsSignaturesModule().then((blsSignatures) => { G2Element } = blsSignatures; - function makehash(msg : Uint8Array) : Uint8Array { - return createHash('sha256').update(msg).digest(); - } - function getSkSeed(): Uint8Array { return Uint8Array.from([ 0, 50, 6, 244, 24, 199, 1, 25, 52, 88, 192, 19, 18, 12, 89, 6, 220, @@ -22,6 +17,7 @@ createBlsSignaturesModule().then((blsSignatures) => { ]); } + /* function getSkBytes(): Uint8Array { return Uint8Array.from([ 55, 112, 145, 240, 231, 40, 70, 59, @@ -30,6 +26,7 @@ createBlsSignaturesModule().then((blsSignatures) => { 41, 197, 144, 139, 113, 81, 163, 45 ]); } + */ function getPkBytes(): Uint8Array { return Uint8Array.from([ @@ -46,10 +43,6 @@ createBlsSignaturesModule().then((blsSignatures) => { return Uint8Array.from([1, 2, 3]); } - function getMessageHash(): Uint8Array { - return Uint8Array.from(createHash('sha256').update(getMessageBytes()).digest()); - } - function getSignatureBytes(): Uint8Array { return Uint8Array.from([ 150, 18, 129, 243, 101, 246, 44, 55, 26, 188, 24, 50, @@ -63,9 +56,11 @@ createBlsSignaturesModule().then((blsSignatures) => { ]); } + /* function getChainCodeBytes(): Uint8Array { return Uint8Array.from([137, 75, 79, 148, 193, 235, 158, 172, 163, 41, 102, 134, 72, 161, 187, 104, 97, 202, 38, 27, 206, 125, 64, 60, 149, 248, 29, 53, 180, 23, 253, 255]); } + */ describe('typings', () => { it('PrivateKey', () => { @@ -73,7 +68,7 @@ createBlsSignaturesModule().then((blsSignatures) => { const sk = AugSchemeMPL.key_gen(getSkSeed()); const aggSk = PrivateKey.aggregate([sk]); const pk = sk.get_g1(); - const bytes: Uint8Array = sk.serialize(); + sk.serialize(); const sig = AugSchemeMPL.sign(sk, getMessageBytes()); ok(AugSchemeMPL.verify(pk, getMessageBytes(), sig)); aggSk.delete(); @@ -85,8 +80,8 @@ createBlsSignaturesModule().then((blsSignatures) => { strictEqual(G1Element.SIZE, 48); const pk = G1Element.from_bytes(getPkBytes()); const aggPk = pk.add(pk); - const fingerprint: number = pk.get_fingerprint(); - const bytes: Uint8Array = pk.serialize(); + pk.get_fingerprint(); + pk.serialize(); pk.delete(); aggPk.delete(); }); @@ -99,7 +94,7 @@ createBlsSignaturesModule().then((blsSignatures) => { const sig2 = G2Element.from_bytes(getSignatureBytes()); const isValid: boolean = AugSchemeMPL.verify(pk, getMessageBytes(), sig); - const serialized: Uint8Array = sig.serialize(); + sig.serialize(); ok(isValid); sig.delete(); aggSig.delete();