►
From YouTube: NEAR Certified Demo | Episode 5.1 -- Off-chain Auth
Description
This demonstration was presented by the author(s) after just 1 week of working with the NEAR platform as part of the NEAR Certified Developer program.
You can find the source code to this demo here:
https://github.com/Learn-NEAR/NCD-05--offchain-auth
---
Follow the latest from NEAR Protocol on:
Website: https://near.org/
Discord: https://near.chat/
Blog: https://near.org/blog/
Twitter: https://twitter.com/NEARProtocol
GitHub: https://github.com/near https://github.com/nearprotocol
#Blockchain #FutureIsNEAR #NEAR #nearprotocol
A
A
C
D
A
D
C
Yeah
I
can
go,
and
also,
I
think,
maybe
only
google
chrome
would
support
the
share
screen.
So
maybe,
if
you're,
using
safari
or
firefox,
it
might
not
work
and
if
you're
using
chromium
it
might
not
work.
I
think
it
might
have
to
be
just
a
good
old,
google,
chrome
or
back.
A
C
Yeah
that
might
not
work
because
they
might
not
have
the
some
kind
of
webrtc
support,
that's
needed,
or
some
kind
of
a
codec
for
like
h.264.
They
might
not
have
like
the
license
for
it.
A
E
Okay,
so.
C
Can
see
the
repo,
I
think
I
should
have
submitted
the
repo
okay,
so
that's
the
repo,
so
a
quick
demo.
I
guess
let's
just
kind
of
look
at
this.
C
We
can
query
the
near
rpc
api
and
see
if
this
access
key
is
actually
indeed
valid
and
if
it's
assigned
to
the
accounting
question.
So
if
you
are
familiar
with
kind
of
public
private
key
cryptography,
what
we're
going
to
do
here
is
generate
a
pseudo
token,
so
we're
just
going
to
make
ed25519
keeper.
So
if
I
hit
this
here,
for
example,
is
our
public
key?
Here's,
our
private
key?
This
is
in
base
58.
C
and
we
are
creating
kind
of
a
jwt
style.
Just
a
json,
and
this
kind
of
this
json
just
makes
some
claims
like
we're
on
year.
Oh
yeah,
so
like
test,
let's
say
like
our
account
is
test
on
year,
so
our
account
is
test.near.
Our
public
key
is
this
so
the
same
key
here
that
belongs
to
this
private
key
and,
for
example,
we'll
just
record
the
epoch.
So
epoch
is
just
kind
of
the
times
number
of
seconds
since
the
assumption
of
unix.
C
So
we
create
this,
and
then
we
generate
something
called
signature
which
takes
pretty
much
this
json
here,
and
this
json
is
like
no
different
than
say
a
written
contract
and
this
signature
no
different
from
putting
your
signature
on
that
contract.
This
is
just
this
kind
of
json
signed.
C
E
C
So
I
lied
and
I
said,
yeah:
oh
there
you
go,
it's
not
really
assuming.
Let
me
see,
okay,
is
that
better?
It.
E
C
String
and
then
we
kind
of
decoded
the
base
58
and
we
produce
we
kind
of
split
it
up.
We
parse
the
json,
so
we
parse
this
inner
thing
here
we
have
our
provider
account
probably
key
or
epoch.
C
Then
we
kind
of
decode
the
signature.
They
call
the
public
key
and
we
feed
it
into
this
function.
Called
signature,
verify
signature,
verify
so
sign
verify
by
tweet
and
acl,
and
it's
going
to
just
literally
return
true
or
false,
the
signature
valid
or
not.
If
the
signature
is
valid
and
our
provider
is
near,
we
go
do
a
post
to
near
and
we
check
if
this
key
is
indeed
tied
to
the
account.
If
it's
not
this
access
key
is
not
on
here.
C
Turn
error
again
on
here:
error:
okay,
so
kind
of
a
quick
rundown,
but
let's
see
it
in
action
right.
So
if
we
go
here
go
to
mainnet,
so
this
is
mainnet.
Let's,
let's
sign
in
to
sputnik
dao,
I'm
going
to
sign
in
just
put
you
down
so
okay.
So
what
is
this?
So?
This
is
our
access
key
for
sputnik
dao
right
here,
and
this
is
kind
of
the
token
we
have
generated
our
off-chain
authentication
token.
C
So,
let's
try
to
this
node.js
server.js
that
we
have
let's
try
sending
an
off
chain
request,
so
this
is
just
going
to
be
carried
in
the
authentication
header.
Let's
see,
can
we
verify
it?
Oh,
okay!
So
all
that
what
we
just
saw.
Yes,
what
we
just
saw
everything
passed.
So
this
signature
is
fully
valid.
This
account
is
indeed
mux.near,
and
this
is
definitely
the
public
key.
That's
associated
to
this
account
the
access
key.
So
let's
try
changing
one
byte
of
this
signature.
So
like
we're
going
to
change
this
y
to
zero,
what
happens?
C
Get
invalid
signature?
Okay.
So
let's
try
one
more
thing:
let's
go
to
our
newer
wallet
yeah
plenty
of
time
and
let's,
let's
revoke
our
access
key.
So
this
is
the
access
key
we
just
made.
Let's
de-authorize
ourselves
from
this
is
the
actual
wallet,
the
actual
contract,
the
blockchain,
and
if
we
try
now
an
off
chain
request,
we
get
account
is
not
tied
to
key.
C
F
Is
is
the
mainnet
like
a
browser
extension
is
this?
Is
that
basically,
a
wrapper
for
this.
F
C
Yeah
so
metamask
it
has
built-in
functions,
kind
of
to
sign
messages
and
stuff,
but
all
metamasks
can
do
for
you
is
generate
you,
this
signature,
so
you
can
definitely
use
metamask
to
have
off-chain
authentication
so
yeah,
it's
very
it's
literally
the
same
thing
as
the
metamask
functionality.
C
If
you
ever
used
openc
and
like
you,
try
to
mint
something,
the
free
open
c,
because
you
know
they
have
the
on
chain
minting
and
the
free
minting.
If
you
do
the
free
minting
you're
going
to
have
a
metamask
pop-up,
that's
going
to
say:
can
you
sign
this
message
to
prove
your
identity?
That's
kind
of
exactly
what
we're
doing
by
signing
this
json.
F
E
C
It's
pretty
simple,
I
mean
you
can
just
look
it
in
the
repo.
It's
two
files.
C
Yeah,
it's
literally
just
this.
I
mean,
if
you're
interested
in
the
actual
sign
verify
it
just
kind
of
looks
like
this,
so
this
is
kind
of
the
guts
of
it
generate
a
random
key
pair
then
create
any
kind
of
text
like
you
can
just
make
a
text
called
sign
me.
C
Then
you
sign
this
text
now
on.
Let's
say
some
backend
or
even
inside,
I'm
not
sure
if
near
supports
verifying
signatures
inside
the
contracts,
but
you
can
verify
that
this
exact
text
was
indeed
signed
by
the
holder
of
this
public
key
so
of
their
secret
key
and
pretty
much
if
valid
is
true.
That
means
that
this
person
signed
this
text
or
this
assertion,
or
this
kind
of
I
like
to
look
at
the
text,
sometimes
as
a
written
agreement
like
let's
say
you
write
something
I'm
going
to
send.
C
B
Okay,
so,
generally
speaking,
this
project
is
not
about
actually
the
smart
contracts
themselves,
but
other
illustrations
that
you
can
actually
use
near
blockchain
and
near
royal
explorer
for
some
other
stuff.
It's
a
pretty
exciting
tour,
correct.