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
e769cd46
Commit
e769cd46
authored
5 years ago
by
Éloïs
Committed by
Cédric Moreau
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[fix] add new functions sign and verify that use upgraded tweetnacl
parent
6f8770c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1283
Resolve "Duniter uses a buggy version of TweetNaCl"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/lib/common-libs/crypto/keyring.ts
+27
-0
27 additions, 0 deletions
app/lib/common-libs/crypto/keyring.ts
with
27 additions
and
0 deletions
app/lib/common-libs/crypto/keyring.ts
+
27
−
0
View file @
e769cd46
...
...
@@ -63,6 +63,20 @@ export class Key {
}
return
encodeBase64
(
sig
)
};
sign
(
msg
:
string
)
{
return
Promise
.
resolve
(
this
.
signSync
(
msg
))
}
signSync
(
msg
:
string
)
{
const
m
=
decodeUTF8
(
msg
);
const
signedMsg
=
nacl
.
sign
(
m
,
this
.
rawSec
());
const
sig
=
new
Uint8Array
(
crypto_sign_BYTES
);
for
(
let
i
=
0
;
i
<
sig
.
length
;
i
++
)
{
sig
[
i
]
=
signedMsg
[
i
];
}
return
encodeBase64
(
sig
)
};
}
export
function
randomKey
()
{
...
...
@@ -98,3 +112,16 @@ export function verifyBuggy(rawMsg:string, rawSig:string, rawPub:string) {
// Call to verification lib...
return
naclBinding
.
verify
(
m
,
sm
,
pub
);
}
/**
* Verify a signature against data & public key.
* Return true of false as callback argument.
*/
export
function
verify
(
rawMsg
:
string
,
rawSig
:
string
,
rawPub
:
string
)
{
const
msg
=
decodeUTF8
(
rawMsg
);
const
sig
=
decodeBase64
(
rawSig
);
const
pub
=
Base58decode
(
rawPub
);
// Call to verification lib...
return
nacl
.
sign
.
detached
.
verify
(
msg
,
sig
,
pub
);
}
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