FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bitcore/PrivateKey.js at master · desertfx/bitcore · GitHub
desertfx
bitcore
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
bitcore
/
PrivateKey.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (60 loc) · 1.92 KB
Breadcrumbs
bitcore
/
PrivateKey.js
Copy path
File metadata and controls
67 lines (60 loc) · 1.92 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
67
require
(
'classtool'
)
;
function
ClassSpec
(
b
)
{
var
superclass
=
b
.
superclass
||
require
(
'./util/VersionedData'
)
.
class
(
)
;
//compressed is true if public key is compressed; false otherwise
function
PrivateKey
(
version
,
buf
,
compressed
)
{
PrivateKey
.
super
(
this
,
arguments
)
;
if
(
compressed
!==
undefined
)
this
.
compressed
(
compressed
)
;
}
;
PrivateKey
.
superclass
=
superclass
;
superclass
.
applyEncodingsTo
(
PrivateKey
)
;
PrivateKey
.
prototype
.
validate
=
function
(
)
{
this
.
doAsBinary
(
function
(
)
{
PrivateKey
.
super
(
this
,
'validate'
,
arguments
)
;
if
(
this
.
data
.
length
<
32
||
(
this
.
data
.
length
>
1
+
32
&&
!
this
.
compressed
(
)
)
||
(
this
.
data
.
length
==
1
+
32
+
1
&&
this
.
data
[
1
+
32
+
1
-
1
]
!=
1
)
||
this
.
data
.
length
>
1
+
32
+
1
)
throw
new
Error
(
'invalid data length'
)
;
}
)
;
}
;
// get or set the payload data (as a Buffer object)
// overloaded from VersionedData
PrivateKey
.
prototype
.
payload
=
function
(
data
)
{
if
(
data
)
{
this
.
doAsBinary
(
function
(
)
{
data
.
copy
(
this
.
data
,
1
)
;
}
)
;
return
data
;
}
var
buf
=
this
.
as
(
'binary'
)
;
if
(
buf
.
length
==
1
+
32
+
1
)
return
buf
.
slice
(
1
,
1
+
32
)
;
else
if
(
buf
.
length
==
1
+
32
)
return
buf
.
slice
(
1
)
;
}
;
// get or set whether the corresponding public key is compressed
PrivateKey
.
prototype
.
compressed
=
function
(
compressed
)
{
if
(
compressed
!==
undefined
)
{
this
.
doAsBinary
(
function
(
)
{
var
len
=
1
+
32
+
1
;
if
(
compressed
)
{
var
data
=
new
Buffer
(
len
)
;
this
.
data
.
copy
(
data
)
;
this
.
data
=
data
;
this
.
data
[
len
-
1
]
=
1
;
}
else
{
this
.
data
=
this
.
data
.
slice
(
0
,
len
-
1
)
;
}
}
)
;
}
else
{
var
len
=
1
+
32
+
1
;
var
data
=
this
.
as
(
'binary'
)
;
if
(
data
.
length
==
len
&&
data
[
len
-
1
]
==
1
)
return
true
;
else
if
(
data
.
length
==
len
-
1
)
return
false
;
else
throw
new
Error
(
'invalid private key'
)
;
}
}
;
return
PrivateKey
;
}
;
module
.
defineClass
(
ClassSpec
)
;
Back
|
FazBrowse Home
|
New Git URL