This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from jimni1222/deCompress
Implemented decompressPublicKey in utils
- Loading branch information
Showing
6 changed files
with
122 additions
and
122 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
Copyright 2018 The caver-js Authors | ||
This file is part of the caver-js library. | ||
The caver-js library is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
The caver-js library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with the caver-js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
const { expect } = require('./extendedChai') | ||
|
||
const Caver = require('../index.js') | ||
|
||
const caver = new Caver() | ||
|
||
const testCases = [ | ||
{ | ||
uncompressed: | ||
'0xdbac81e8486d68eac4e6ef9db617f7fbd79a04a3b323c982a09cdfc61f0ae0e8906d7170ba349c86879fb8006134cbf57bda9db9214a90b607b6b4ab57fc026e', | ||
compressed: '0x02dbac81e8486d68eac4e6ef9db617f7fbd79a04a3b323c982a09cdfc61f0ae0e8', | ||
}, | ||
{ | ||
uncompressed: | ||
'0x6b9edd63b1bb0ed12c7de51d9a7d672e97f6a937c371a545dfc5acf3799ccbf19a692c368625f0f43a17201517123b7e26d53ef722f012c893ab4a5f865f50b2', | ||
compressed: '0x026b9edd63b1bb0ed12c7de51d9a7d672e97f6a937c371a545dfc5acf3799ccbf1', | ||
}, | ||
{ | ||
uncompressed: | ||
'0x93e9b3177137bb792fa5ebcb3cece17121f81bfb8ae39f6a5c4074b9ca207b96a645fac91e884df17f335d2908eaf103675d12eb327768e816060d1f65c25ac8', | ||
compressed: '0x0293e9b3177137bb792fa5ebcb3cece17121f81bfb8ae39f6a5c4074b9ca207b96', | ||
}, | ||
{ | ||
uncompressed: | ||
'0x1e7bcc70c72770dbb72fea022e8a6d07f814d2ebe4de9ae3f7af75bf706902a7b73ff919898c836396a6b0c96812c3213b99372050853bd1678da0ead14487d7', | ||
compressed: '0x031e7bcc70c72770dbb72fea022e8a6d07f814d2ebe4de9ae3f7af75bf706902a7', | ||
}, | ||
{ | ||
uncompressed: | ||
'0xc5ae07417506b7351379f43b8745327d5e5bffecaa209109b03820072d02d6185cf4e5c13397d82e4b8ba9681fa093fc2a1d8788c19d89e4b024ca41b8a66067', | ||
compressed: '0x03c5ae07417506b7351379f43b8745327d5e5bffecaa209109b03820072d02d618', | ||
}, | ||
] | ||
|
||
describe('caver.utils.compressPublicKey', () => { | ||
it('CAVERJS-UNIT-SER-022 : Should return compressed public key if the argument is uncompressed public key', () => { | ||
expect(caver.utils.compressPublicKey(testCases[0].uncompressed)).to.equal(testCases[0].compressed) | ||
expect(caver.utils.compressPublicKey(testCases[1].uncompressed)).to.equal(testCases[1].compressed) | ||
expect(caver.utils.compressPublicKey(testCases[2].uncompressed)).to.equal(testCases[2].compressed) | ||
expect(caver.utils.compressPublicKey(testCases[3].uncompressed)).to.equal(testCases[3].compressed) | ||
expect(caver.utils.compressPublicKey(testCases[4].uncompressed)).to.equal(testCases[4].compressed) | ||
}) | ||
|
||
it('CAVERJS-UNIT-SER-023 : Should return same one with the argument if the argument is compressed public key', () => { | ||
expect(caver.utils.compressPublicKey(testCases[0].compressed)).to.equal(testCases[0].compressed) | ||
expect(caver.utils.compressPublicKey(testCases[1].compressed)).to.equal(testCases[1].compressed) | ||
expect(caver.utils.compressPublicKey(testCases[2].compressed)).to.equal(testCases[2].compressed) | ||
expect(caver.utils.compressPublicKey(testCases[3].compressed)).to.equal(testCases[3].compressed) | ||
expect(caver.utils.compressPublicKey(testCases[4].compressed)).to.equal(testCases[4].compressed) | ||
}) | ||
}) | ||
|
||
describe('caver.utils.isCompressedPublicKey', () => { | ||
it('CAVERJS-UNIT-SER-025: Should return false if the argument is uncompressed public key', () => { | ||
expect(caver.utils.isCompressedPublicKey(testCases[0].uncompressed)).to.be.false | ||
expect(caver.utils.isCompressedPublicKey(testCases[1].uncompressed)).to.be.false | ||
expect(caver.utils.isCompressedPublicKey(testCases[2].uncompressed)).to.be.false | ||
expect(caver.utils.isCompressedPublicKey(testCases[3].uncompressed)).to.be.false | ||
expect(caver.utils.isCompressedPublicKey(testCases[4].uncompressed)).to.be.false | ||
}) | ||
|
||
it('CAVERJS-UNIT-SER-026: Should return true if the argument is compressed public key', () => { | ||
expect(caver.utils.isCompressedPublicKey(testCases[0].compressed)).to.be.true | ||
expect(caver.utils.isCompressedPublicKey(testCases[1].compressed)).to.be.true | ||
expect(caver.utils.isCompressedPublicKey(testCases[2].compressed)).to.be.true | ||
expect(caver.utils.isCompressedPublicKey(testCases[3].compressed)).to.be.true | ||
expect(caver.utils.isCompressedPublicKey(testCases[4].compressed)).to.be.true | ||
}) | ||
}) | ||
|
||
describe('caver.utils.decompressPublicKey', () => { | ||
it('CAVERJS-UNIT-SER-066: Should return uncompressed public key if the argument is compressed public key', () => { | ||
expect(caver.utils.decompressPublicKey(testCases[0].compressed)).to.equal(testCases[0].uncompressed) | ||
expect(caver.utils.decompressPublicKey(testCases[1].compressed)).to.equal(testCases[1].uncompressed) | ||
expect(caver.utils.decompressPublicKey(testCases[2].compressed)).to.equal(testCases[2].uncompressed) | ||
expect(caver.utils.decompressPublicKey(testCases[3].compressed)).to.equal(testCases[3].uncompressed) | ||
expect(caver.utils.decompressPublicKey(testCases[4].compressed)).to.equal(testCases[4].uncompressed) | ||
}) | ||
|
||
it('CAVERJS-UNIT-SER-067: Should return same one with the argument if the argument is uncompressed public key', () => { | ||
expect(caver.utils.decompressPublicKey(testCases[0].uncompressed)).to.equal(testCases[0].uncompressed) | ||
expect(caver.utils.decompressPublicKey(testCases[1].uncompressed)).to.equal(testCases[1].uncompressed) | ||
expect(caver.utils.decompressPublicKey(testCases[2].uncompressed)).to.equal(testCases[2].uncompressed) | ||
expect(caver.utils.decompressPublicKey(testCases[3].uncompressed)).to.equal(testCases[3].uncompressed) | ||
expect(caver.utils.decompressPublicKey(testCases[4].uncompressed)).to.equal(testCases[4].uncompressed) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.