Platform
Resources
Pricing
Sign in
Get started
varokas
Workspace
Fork
Published
By
varokas
Edited
May 3, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//Try: Changing this value
register
=
(
{
username
:
'myuser'
,
password
:
'mypassword'
}
)
Insert cell
//Try: Running this cell multiple times to see different (verifier,salt) for the same (username,password)
verifyToken
=
createClient
(
register
)
.
then
(
client
=>
createVerifier
(
client
)
)
Insert cell
Insert cell
passwordStore
=
(
{
[
register
.
username
]
:
verifyToken
}
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
lookedUpVerifyToken
=
passwordStore
[
login
.
username
]
Insert cell
Insert cell
//Try: Running this cell multiple times to see different publicKey from random value
server
=
createServer
(
lookedUpVerifyToken
)
Insert cell
serverPublicKey
=
server
.
getPublicKey
(
)
Insert cell
Insert cell
serverSalt
=
passwordStore
[
login
.
username
]
.
salt
Insert cell
Insert cell
// Try: Change this value to simulate login failed.
login
=
(
{
username
:
'myuser'
,
password
:
'mypassword'
}
)
Insert cell
//Try: Running this cell multiple times to see different publicKey and clientProof from random value
client
=
createClient
(
login
)
Insert cell
Insert cell
clientProof
=
{
client
.
setSalt
(
serverSalt
)
;
client
.
setServerPublicKey
(
serverPublicKey
)
;
return
client
.
getProof
(
)
}
Insert cell
clientPublicKey
=
client
.
getPublicKey
(
)
Insert cell
Insert cell
{
server
.
setClientPublicKey
(
clientPublicKey
)
return
server
.
checkClientProof
(
clientProof
)
}
Insert cell
Insert cell
Insert cell
Insert cell
function
createVerifier
(
client
)
{
return
new
Promise
(
(
resolve
,
reject
)
=>
{
client
.
createVerifier
(
(
err
,
result
)
=>
{
if
(
!
err
)
resolve
(
result
)
;
else
reject
(
err
)
;
}
)
}
)
}
Insert cell
function
createClient
(
cred
)
{
return
new
Promise
(
resolve
=>
{
var
client
=
new
jsrp
.
client
(
)
;
client
.
init
(
cred
,
(
)
=>
resolve
(
client
)
)
;
}
)
}
Insert cell
function
createServer
(
v
)
{
return
new
Promise
(
resolve
=>
{
var
server
=
new
jsrp
.
server
(
)
;
server
.
init
(
v
,
(
)
=>
resolve
(
server
)
)
;
}
)
}
Insert cell
short
=
(
str
)
=>
str
.
length
>
15
?
str
.
substring
(
0
,
15
)
+
"..."
:
str
;
Insert cell
print
=
(
obj
)
=>
"("
+
Object
.
entries
(
obj
)
.
map
(
(
e
)
=>
e
[
0
]
+
"="
+
label
(
e
[
1
]
)
)
+
")"
Insert cell
label
=
(
str
)
=>
"<span style='background-color: #CCCCCC'>"
+
trunc
(
str
)
+
"</span>"
Insert cell
trunc
=
(
str
)
=>
str
.
length
>
10
?
str
.
substring
(
0
,
10
)
:
str
;
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
register
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
verifyToken
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
passwordStore
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
lookedUpVerifyToken
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
server
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
serverPublicKey
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
serverSalt
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
login
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
client
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
clientProof
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
clientPublicKey
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
jsrp
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
createVerifier
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
createClient
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
createServer
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
short
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
print
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
label
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
trunc
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML