Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
timothe
duniter
Commits
e769cd46
Commit
e769cd46
authored
Dec 15, 2019
by
Éloïs
Committed by
Cédric Moreau
Jan 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix] add new functions sign and verify that use upgraded tweetnacl
parent
6f8770c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
app/lib/common-libs/crypto/keyring.ts
app/lib/common-libs/crypto/keyring.ts
+27
-0
No files found.
app/lib/common-libs/crypto/keyring.ts
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
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment