-
Notifications
You must be signed in to change notification settings - Fork 196
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
1 parent
00c62b1
commit 44b644f
Showing
8 changed files
with
80 additions
and
19 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 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { | ||
sha256, | ||
hashToHex, | ||
ripemd160, | ||
decompressPubKey, | ||
privateKeyToPublicKey, | ||
} from './crypto.js' | ||
|
||
describe('crypto helper functions', () => { | ||
it('hashToHex returns correct value', () => { | ||
const message = 'hello world' | ||
const expected = | ||
'8D93BD1A4B536FE30D0AA7D4FD0B43F4964A91059A1FB0014D8F3F4E575B38AB' | ||
const actual = hashToHex(message) | ||
|
||
expect(actual).toEqual(expected) | ||
}) | ||
|
||
it('sha256 returns correct value', () => { | ||
const message = 'hello world' | ||
const expected = | ||
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9' | ||
const actual = sha256(Buffer.from(message)) | ||
|
||
expect(Buffer.from(actual).toString('hex')).toEqual(expected) | ||
}) | ||
|
||
it('ripemd160 returns correct value', () => { | ||
const message = 'hello world' | ||
const expected = '98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f' | ||
const actual = ripemd160(Buffer.from(message)) | ||
|
||
expect(Buffer.from(actual).toString('hex')).toEqual(expected) | ||
}) | ||
|
||
it('privateKeyToPublicKey returns correct value', () => { | ||
const privateKey = | ||
'f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3' | ||
const expected = 'A13cTVZCuTg+Lwh7LuiLcgf2KG68nzEOnfFAbszCwxgT' | ||
const actual = privateKeyToPublicKey(Buffer.from(privateKey, 'hex')) | ||
|
||
expect(Buffer.from(actual).toString('base64')).toEqual(expected) | ||
}) | ||
|
||
it('decompressPubKey returns correct value', () => { | ||
const publicKey = | ||
'035ddc4d5642b9383e2f087b2ee88b7207f6286ebc9f310e9df1406eccc2c31813' | ||
const expected = | ||
'3564646334643536343262393338336532663038376232656538386237323037663632383665626339663331306539646631343036656363633263333138313334646637633662643665663761623466613261376332663265356432623630636334333862616164343331386165386637333636613364323137653939636337' | ||
const actual = decompressPubKey(publicKey) | ||
|
||
expect(Buffer.from(actual).toString('hex')).toEqual(expected) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5124,6 +5124,11 @@ | |
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/crypto-js@^4.2.2": | ||
version "4.2.2" | ||
resolved "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz#771c4a768d94eb5922cc202a3009558204df0cea" | ||
integrity sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ== | ||
|
||
"@types/debug@^4.1.7": | ||
version "4.1.12" | ||
resolved "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz#a155f21690871953410df4b6b6f53187f0500917" | ||
|
@@ -8001,9 +8006,9 @@ crypto-browserify@^3.12.0: | |
randombytes "^2.0.0" | ||
randomfill "^1.0.3" | ||
|
||
[email protected]: | ||
[email protected], crypto-js@^4.2.0: | ||
version "4.2.0" | ||
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631" | ||
resolved "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631" | ||
integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q== | ||
|
||
crypto-js@^3.3.0: | ||
|
@@ -11760,11 +11765,6 @@ jsbi@^3.1.5: | |
resolved "https://registry.npmjs.org/jsbi/-/jsbi-3.2.5.tgz#b37bb90e0e5c2814c1c2a1bcd8c729888a2e37d6" | ||
integrity sha512-aBE4n43IPvjaddScbvWRA2YlTzKEynHzu7MqOyTipdHucf/VxS63ViCjxYRg86M8Rxwbt/GfzHl1kKERkt45fQ== | ||
|
||
jscrypto@^1.0.3: | ||
version "1.0.3" | ||
resolved "https://registry.npmjs.org/jscrypto/-/jscrypto-1.0.3.tgz#598febca2a939d6f679c54f56e1fe364cef30cc9" | ||
integrity sha512-lryZl0flhodv4SZHOqyb1bx5sKcJxj0VBo0Kzb4QMAg3L021IC9uGpl0RCZa+9KJwlRGSK2C80ITcwbe19OKLQ== | ||
|
||
jsesc@^2.5.1: | ||
version "2.5.2" | ||
resolved "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4" | ||
|