FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bitcore/test/test.Message.js at master · jonasbits/bitcore · GitHub
jonasbits
/
bitcore
Public
forked from
bitpay/bitcore
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
bitcore
/
test
/
test.Message.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (54 loc) · 2.12 KB
Breadcrumbs
bitcore
/
test
/
test.Message.js
Copy path
File metadata and controls
66 lines (54 loc) · 2.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict'
;
var
chai
=
chai
||
require
(
'chai'
)
;
var
should
=
chai
.
should
(
)
;
var
bitcore
=
bitcore
||
require
(
'../bitcore'
)
;
var
Message
=
bitcore
.
Message
;
var
coinUtil
=
bitcore
.
util
;
describe
(
'Message'
,
function
(
)
{
describe
(
'sign'
,
function
(
)
{
it
(
'should return a signature'
,
function
(
)
{
var
key
=
bitcore
.
Key
.
generateSync
(
)
;
var
sig
=
Message
.
sign
(
'my message'
,
key
)
;
sig
.
length
.
should
.
be
.
greaterThan
(
0
)
;
}
)
;
it
(
'should not sign a message the same way twice'
,
function
(
)
{
var
key
=
new
bitcore
.
Key
(
)
;
key
.
private
=
coinUtil
.
sha256
(
'a fake private key'
)
;
key
.
regenerateSync
(
)
;
var
sig1
=
Message
.
sign
(
'my message'
,
key
)
;
var
sig2
=
Message
.
sign
(
'my message'
,
key
)
;
sig1
.
toString
(
'hex'
)
.
should
.
not
.
equal
(
sig2
.
toString
(
'hex'
)
)
;
}
)
;
}
)
;
describe
(
'verifyWithPubKey'
,
function
(
)
{
it
(
'should verify a signed message'
,
function
(
)
{
var
message
=
'my message'
;
var
key
=
bitcore
.
Key
.
generateSync
(
)
;
var
sig
=
Message
.
sign
(
message
,
key
)
;
Message
.
verifyWithPubKey
(
key
.
public
,
message
,
sig
)
.
should
.
equal
(
true
)
;
}
)
;
}
)
;
describe
(
'magicBytes'
,
function
(
)
{
it
(
'should be "Bitcoin Signed Message:\\n"'
,
function
(
)
{
Message
.
magicBytes
.
toString
(
)
.
should
.
equal
(
'Bitcoin Signed Message:\n'
)
;
}
)
;
}
)
;
describe
(
'magicHash'
,
function
(
)
{
it
(
'should hash the message with the magic bytes'
,
function
(
)
{
var
str
=
'my message'
;
var
magicBytes
=
Message
.
magicBytes
;
var
prefix1
=
coinUtil
.
varIntBuf
(
magicBytes
.
length
)
;
var
message
=
new
Buffer
(
str
)
;
var
prefix2
=
coinUtil
.
varIntBuf
(
message
.
length
)
;
var
buf
=
Buffer
.
concat
(
[
prefix1
,
magicBytes
,
prefix2
,
message
]
)
;
var
hash
=
coinUtil
.
twoSha256
(
buf
)
;
var
hash2
=
Message
.
magicHash
(
str
)
;
hash
.
toString
(
)
.
should
.
equal
(
hash2
.
toString
(
)
)
;
}
)
;
it
(
'should hash this message the same way as bitcoinjs-lib'
,
function
(
)
{
var
hashHex
=
'74eacdc6c04724869380907bf4aab561a1494a4a800fba266b29b8158c2c4cec'
;
var
str
=
'this is a test message'
;
hashHex
.
should
.
equal
(
Message
.
magicHash
(
str
)
.
toString
(
'hex'
)
)
;
}
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL