Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
46c25f3b
Commit
46c25f3b
authored
5 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[enh] scrypt: keypair generation use duniteroxyde instead of tweetnacl
parent
01690ecf
No related branches found
No related tags found
1 merge request
!1292
Feature/oxyde crypto
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/modules/keypair/lib/scrypt.ts
+10
-17
10 additions, 17 deletions
app/modules/keypair/lib/scrypt.ts
with
10 additions
and
17 deletions
app/modules/keypair/lib/scrypt.ts
+
10
−
17
View file @
46c25f3b
...
...
@@ -11,11 +11,8 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
import
{
Base58encode
}
from
"
../../../lib/common-libs/crypto/base58
"
import
{
decodeBase64
}
from
"
../../../lib/common-libs/crypto/nacl-util
"
import
*
as
crypto
from
'
crypto
'
const
nacl
=
require
(
'
tweetnacl
'
);
import
{
KeyPairBuilder
,
seedToSecretKey
}
from
'
duniteroxyde
'
const
SEED_LENGTH
=
32
;
// Length of the key
...
...
@@ -29,20 +26,16 @@ const SEED_LENGTH = 32; // Length of the key
* @return keyPair An object containing the public and private keys, base58 encoded.
*/
export
const
Scrypt
=
async
(
salt
:
string
,
key
:
string
,
N
=
4096
,
r
=
16
,
p
=
1
)
=>
{
const
keyBytes
=
await
getScryptKey
(
key
,
salt
,
N
,
r
,
p
)
const
pair
=
nacl
.
sign
.
keyPair
.
fromSeed
(
keyBytes
);
return
{
pub
:
Base58encode
(
new
Buffer
(
pair
.
publicKey
,
'
hex
'
)),
sec
:
Base58encode
(
new
Buffer
(
pair
.
secretKey
,
'
hex
'
))
};
}
const
getScryptKey
=
async
(
key
:
string
,
salt
:
string
,
N
:
number
,
r
:
number
,
p
:
number
)
=>
{
const
res
:
any
=
await
new
Promise
((
resolve
,
reject
)
=>
{
crypto
.
scrypt
(
key
,
salt
,
SEED_LENGTH
,
{
N
,
r
,
p
},
(
err
:
any
,
res
:
Buffer
)
=>
{
const
res
:
{
pub
:
string
,
sec
:
string
}
=
await
new
Promise
((
resolve
,
reject
)
=>
{
crypto
.
scrypt
(
key
,
salt
,
SEED_LENGTH
,
{
N
,
r
,
p
},
(
err
:
any
,
seed
:
Buffer
)
=>
{
if
(
err
)
return
reject
(
err
)
resolve
(
res
)
const
pair
=
KeyPairBuilder
.
fromSeed
(
seed
);
resolve
({
pub
:
pair
.
getPublicKey
(),
sec
:
seedToSecretKey
(
seed
)
})
})
})
return
decodeBase64
(
res
.
toString
(
"
base64
"
))
return
res
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment