FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bitcore/WalletKey.js at master · ecto/bitcore · GitHub
ecto
bitcore
Repository navigation
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
52 lines (45 loc) · 1.47 KB
Breadcrumbs
bitcore
/
WalletKey.js
Copy path
File metadata and controls
52 lines (45 loc) · 1.47 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
var
imports
=
require
(
'soop'
)
.
imports
(
)
;
var
coinUtil
=
require
(
'./util/util'
)
;
var
timeUtil
=
require
(
'./util/time'
)
;
var
Key
=
require
(
'./Key'
)
;
var
PrivateKey
=
require
(
'./PrivateKey'
)
;
var
Address
=
require
(
'./Address'
)
;
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
=
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
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
(
)
;
}
;
module
.
exports
=
require
(
'soop'
)
(
WalletKey
)
;
Back
|
FazBrowse Home
|
New Git URL