18.0.4
Single sign on and authentication without third parties or remote servers.
Generates an authentication request and redirects the user to the Blockstack browser to approve the sign in request.
Please note that this requires that the web browser properly handles the
blockstack:
URL protocol handler.
Most applications should use this
method for sign in unless they require more fine grained control over how the
authentication request is generated. If your app falls into this category,
use generateAndStoreTransitKey
, makeAuthRequest
,
and redirectToSignInWithAuthRequest
to build your own sign in process.
(String
= `${window.location.origin}/`
)
The location to which the identity provider will redirect the user after
the user approves sign in.
(String
= `${window.location.origin}/manifest.json`
)
Location of the manifest file.
(Array
= DEFAULT_SCOPE
)
Defaults to requesting write access to
this app's data store.
An array of strings indicating which permissions this app is requesting.
void
:
Check if there is a authentication request that hasn't been handled.
Boolean
:
true
if there is a pending sign in, otherwise
false
Try to process any pending sign in request by returning a Promise
that resolves
to the user data object if the sign in succeeds.
(String
= 'https://core.blockstack.org/v1/names/'
)
the endpoint against which to verify public
keys match claimed username
(String
= getAuthResponseToken()
)
the signed authentication response token
(String
= getTransitKey()
)
the transit private key that corresponds to the transit public key
that was provided in the authentication request
Promise
:
that resolves to the user data object if successful and rejects
if handling the sign in request fails or there was no pending sign in request.
Retrieves the user data object. The user's profile is stored in the key profile
.
Object
:
User data object.
Check if a user is currently signed in.
Boolean
:
true
if the user is signed in,
false
if not.
Sign the user out and optionally redirect to given location.
(String
= null
)
Location to redirect user to after sign out.
void
:
Generates an authentication request that can be sent to the Blockstack
browser for the user to approve sign in. This authentication request can
then be used for sign in by passing it to the redirectToSignInWithAuthRequest
method.
Note: This method should only be used if you want to roll your own authentication
flow. Typically you'd use redirectToSignIn
which takes care of this
under the hood.
(String
= generateAndStoreTransitKey()
)
hex encoded transit
private key
(String
= `${window.location.origin}/`
)
location to redirect user to after sign in approval
(String
= `${window.location.origin}/manifest.json`
)
location of this app's manifest file
(String
= window.location.origin
)
the origin of this app
(Number
= nextHour().getTime()
)
the time at which this request is no longer valid
String
:
the authentication request
Redirects the user to the Blockstack browser to approve the sign in request given.
The user is redirected to the blockstackIDHost
if the blockstack:
protocol handler is not detected. Please note that the protocol handler detection
does not work on all browsers.
(String
= DEFAULT_BLOCKSTACK_HOST
)
the URL to redirect the user to if the blockstack
protocol handler is not detected
void
:
Retrieve the authentication token from the URL query
String
:
the authentication token if it exists otherwise
null
Identity you own and control.
Extracts a profile from an encoded token and optionally verifies it,
if publicKeyOrAddress
is provided.
(String)
the token to be extracted
(String
= null
)
the public key or address of the
keypair that is thought to have signed the token
Object
:
the profile extracted from the encoded token
publicKeyOrAddress
Wraps a token for a profile token file
(String)
the token to be wrapped
Object
:
including
token
and
decodedToken
Signs a profile token
(Object)
the JSON of the profile to be signed
(String)
the signing private key
(Object
= null
)
the entity that the information is about
(Object
= null
)
the entity that is issuing the token
(String
= 'ES256K'
)
the signing algorithm to use
(Date
= new Date()
)
the time of issuance of the token
(Date
= nextYear()
)
the time of expiration of the token
Object
:
the signed profile token
Verifies a profile token
(String)
the token to be verified
(String)
the public key or address of the
keypair that is thought to have signed the token
Object
:
the verified, decoded profile token
Validates the social proofs in a user's profile. Currently supports validation of Facebook, Twitter, GitHub, Instagram, LinkedIn and HackerNews accounts.
(Object)
The JSON of the profile to be validated
(string)
The owner bitcoin address to be validated
(string
= null
)
The Blockstack name to be validated
Promise
:
that resolves to an array of validated proof objects
Look up a user profile by blockstack ID
(string)
The Blockstack ID of the profile to look up
(string
= null
)
The URL
to use for zonefile lookup. If falsey, lookupProfile will use the
blockstack.js getNameInfo function.
Promise
:
that resolves to a profile object
Store your app's data without servers in storage your user controls.
Note: Blockstack Gaia Storage APIs and on-disk format will change in upcoming pre-releases breaking backward compatibility. File encryption is currently opt-in on a file by file basis.
Certain storage features such as and collections are not implemented in the current version. These features will be rolled out in future updates.
Retrieves the specified file from the app's data store.
(String)
the path to the file to read
(Object
= null
)
options object
Name | Description |
---|---|
options.decrypt Boolean
(default true )
|
try to decrypt the data with the app private key |
options.username String
|
the Blockstack ID to lookup for multi-player storage |
options.verify Boolean
|
Whether the content should be verified, only to be used
when
putFile
was set to
sign = true
|
options.app String
|
the app to lookup for multi-player storage - defaults to current origin |
options.zoneFileLookupURL String
(default null )
|
The URL to use for zonefile lookup. If falsey, this will use the blockstack.js's getNameInfo function instead. |
Promise
:
that resolves to the raw data in the file
or rejects with an error
Stores the data provided in the app's data store to to the file specified.
(String)
the path to store the data in
Promise
:
that resolves if the operation succeed and rejects
if it failed
Encrypts the data provided with the app public key.
String
:
Stringified ciphertext object
Decrypts data encrypted with encryptContent
with the
transit private key.
(String | Buffer)
:
decrypted content.
Get the app storage bucket URL
(String)
the gaia hub URL
(String)
the app private key used to generate the app address
Promise
:
That resolves to the URL of the app index file
or rejects if it fails
Fetch the public read URL of a user file for the specified app.
(String)
the path to the file to read
(String)
The Blockstack ID of the user to look up
(String)
The app origin
(String
= null
)
The URL
to use for zonefile lookup. If falsey, this will use the
blockstack.js's getNameInfo function instead.
Promise
:
that resolves to the public read URL of the file
or rejects with an error
Generate and broadcast Blockstack blockchain transactions.
Decrypts the hex encrypted private key
(String)
the private key corresponding to the public
key for which the ciphertext was encrypted
(String)
the ciphertext
String
:
the decrypted private key
Generates a signed authentication response token for an app. This token is sent back to apps which use contents to access the resources and data requested by the app.
(String)
the identity key of the Blockstack ID generating
the authentication response
(Object
= {}
)
the profile object for the Blockstack ID
(AuthMetadata)
an object containing metadata sent as part of the authentication
response including
email
if requested and available and a URL to the profile
(String
= null
)
core session token when responding to a legacy auth request
or
null
for current direct to gaia authentication requests
(String
= null
)
the application private key. This private key is
unique and specific for every Blockstack ID and application combination.
(Number
= nextMonth().getTime()
)
an integer in the same format as
new Date().getTime()
, milliseconds since the Unix epoch
(String
= null
)
the public key provide by the app
in its authentication request with which secrets will be encrypted
(String
= null
)
URL to the write path of the user's Gaia hub
String
:
signed and encoded authentication response token
Checks if the expiration date of the token
is before the current time
(String)
encoded and signed authentication token
Boolean
:
true
if the
token
has not yet expired,
false
if the
token
has expired
Makes sure the redirect_uri
is a same origin absolute URL.
(String)
encoded and signed authentication token
Boolean
:
true
if valid, otherwise
false
Sign content using ECDSA
Object
:
contains:
signature - Hex encoded DER signature
public key - Hex encoded private string taken from privateKey
Verify content using ECDSA
Boolean
:
returns true when signature matches publickey + content, false if not
Broadcasts a signed bitcoin transaction to the network optionally waiting to broadcast the transaction until a second transaction has a certain number of confirmations.
(string)
the hex-encoded transaction to broadcast
(string
= null
)
the hex transaction id of the transaction to watch for
the specified number of confirmations before broadcasting the
transaction
(number
= 6
)
the number of confirmations
transactionToWatch
must have
before broadcasting
transaction
.
Promise<(Object | Error)>
:
Returns a Promise that resolves to an object with a
transaction_hash
key containing the transaction hash of the broadcasted transaction.
In the event of an error, it rejects with:
RemoteServiceError
if there is a problem
with the transaction broadcast serviceMissingParameterError
if you call the function without a required
parameterBroadcasts a zone file to the Atlas network via the transaction broadcast service.
(String)
the zone file to be broadcast to the Atlas network
(String
= null
)
the hex transaction id of the transaction
to watch for confirmation before broadcasting the zone file to the Atlas network
Promise<(Object | Error)>
:
Returns a Promise that resolves to an object with a
transaction_hash
key containing the transaction hash of the broadcasted transaction.
In the event of an error, it rejects with:
RemoteServiceError
if there is a problem
with the transaction broadcast serviceMissingParameterError
if you call the function without a required
parameterSends the preorder and registration transactions and zone file for a Blockstack name registration along with the to the transaction broadcast service.
The transaction broadcast:
(String)
the hex-encoded, signed preorder transaction generated
using the
makePreorder
function
(String)
the hex-encoded, signed register transaction generated
using the
makeRegister
function
(String)
the zone file to be broadcast to the Atlas network
Promise<(Object | Error)>
:
Returns a Promise that resolves to an object with a
transaction_hash
key containing the transaction hash of the broadcasted transaction.
In the event of an error, it rejects with:
RemoteServiceError
if there is a problem
with the transaction broadcast serviceMissingParameterError
if you call the function without a required
parameterany
:
version number of the signer, currently, should always be 1
any
:
a string representing the transaction signer's address
(usually Base58 check encoding)
Signs a transaction input
(TransactionBuilder)
the transaction to sign
(number)
the input on the transaction to sign
Class representing a transaction signer for pubkeyhash addresses (a.k.a. single-sig addresses)
(bitcoinjs.ECPair)
Estimates cost of a namesapce reveal transaction for a namespace
(BlockstackNamespace)
the namespace to reveal
(String)
the address to receive the namespace
(this must have been passed as 'revealAddress' to a prior namespace
preorder)
(String)
the address that pays for this transaction
(Number
= 1
)
the number of UTXOs we expect will be required
from the payment address
Promise
:
a promise which resolves to the satoshi cost to
fund the reveal. This includes a 5500 satoshi dust output for the
preorder. Even though this is a change output, the payer must have
enough funds to generate this output, so we include it in the cost.
Estimates the cost of a namespace-ready transaction for a namespace
(String)
the namespace to ready
(Number
= 1
)
the number of UTXOs we expect will
be required from the reveal address
Promise
:
a promise which resolves to the satoshi cost to
fund this namespacey-ready transaction.
Estimates the cost of a name-import transaction
(String)
the fully-qualified name
(String)
the recipient
(String)
the zone file hash
(Number
= 1
)
the number of UTXOs we expect will
be required from the importer address
Promise
:
a promise which resolves to the satoshi cost
to fund this name-import transaction
Estimates the cost of an announce transaction
(String)
the hash of the message
(Number
= 1
)
the number of utxos we expect will
be required from the importer address
Promise
:
a promise which resolves to the satoshi cost
to fund this announce transaction