FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bitcore/WalletKey.js at master · trapp/bitcore · GitHub
trapp
/
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
/
WalletKey.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (48 loc) · 1.61 KB
Breadcrumbs
bitcore
/
WalletKey.js
Copy path
File metadata and controls
55 lines (48 loc) · 1.61 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
require
(
'classtool'
)
;
function
ClassSpec
(
b
)
{
var
coinUtil
=
require
(
'./util/util'
)
;
var
timeUtil
=
require
(
'./util/time'
)
;
var
KeyModule
=
require
(
'./Key'
)
;
var
PrivateKey
=
require
(
'./PrivateKey'
)
.
class
(
)
;
var
Address
=
require
(
'./Address'
)
.
class
(
)
;
function
WalletKey
(
cfg
)
{
if
(
!
cfg
)
cfg
=
{
}
;
if
(
!
cfg
.
network
)
throw
new
Error
(
'network parameter is required'
)
;
this
.
network
=
cfg
.
network
;
// required
this
.
created
=
cfg
.
created
;
this
.
privKey
=
cfg
.
privKey
;
}
;
WalletKey
.
prototype
.
generate
=
function
(
)
{
this
.
privKey
=
KeyModule
.
Key
.
generateSync
(
)
;
this
.
created
=
timeUtil
.
curtime
(
)
;
}
;
WalletKey
.
prototype
.
storeObj
=
function
(
)
{
var
pubKey
=
this
.
privKey
.
public
.
toString
(
'hex'
)
;
var
pubKeyHash
=
coinUtil
.
sha256ripe160
(
this
.
privKey
.
public
)
;
var
addr
=
new
Address
(
this
.
network
.
addressPubkey
,
pubKeyHash
)
;
var
priv
=
new
PrivateKey
(
this
.
network
.
keySecret
,
this
.
privKey
.
private
,
this
.
privKey
.
compressed
)
;
var
obj
=
{
created
:
this
.
created
,
priv
:
priv
.
toString
(
)
,
pub
:
pubKey
,
addr
:
addr
.
toString
(
)
,
}
;
return
obj
;
}
;
WalletKey
.
prototype
.
fromObj
=
function
(
obj
)
{
this
.
created
=
obj
.
created
;
this
.
privKey
=
new
KeyModule
.
Key
(
)
;
if
(
obj
.
priv
.
length
==
64
)
{
this
.
privKey
.
private
=
new
Buffer
(
obj
.
priv
,
'hex'
)
;
this
.
privKey
.
compressed
=
true
;
}
else
{
var
priv
=
new
PrivateKey
(
obj
.
priv
)
;
this
.
privKey
.
private
=
new
Buffer
(
priv
.
payload
(
)
)
;
this
.
privKey
.
compressed
=
priv
.
compressed
(
)
;
}
this
.
privKey
.
regenerateSync
(
)
;
}
;
return
WalletKey
;
}
;
module
.
defineClass
(
ClassSpec
)
;
Back
|
FazBrowse Home
|
New Git URL