Decrypt an encrypted mnemonic phrase with a password. Legacy triplesec encrypted payloads are also supported.
Password for data
the raw mnemonic phrase
Derive the configPrivateKey
for a wallet.
This key is derived from the path m/5757'/0'/1
, using 1
for change option, following the bip44 recommendation
for keys relating to non-public data.
This key is used to encrypt configuration data related to a wallet, so the user's configuration can be synced across wallets.
A keychain that was created using the wallet's seed phrase
Before the Stacks Wallet, the authenticator used with Connect used a different format and path for the config file.
The path for this key is m/45'
A keychain that was created using the wallet's seed phrase
Generate a salt, which is used for generating an app-specific private key
Encrypt a raw mnemonic phrase to be password protected
Raw mnemonic phrase
Password to encrypt mnemonic with
The encrypted phrase
A private key used to encrypt configuration data
The encrypted secret key
The private key associated with the root of a BIP39 keychain
Used when generating app private keys, which encrypt app-specific data
Get the display name of an account.
If the account has a username, it will return the first part of the username, so myname.id
=> myname
, and
myname.blockstack.id
=> myname
.
If the account has no username, it returns Account ${acount.index}
Restore wallet accounts by checking for encrypted WalletConfig files, stored in Gaia.
This helps provide a better UX for users, so we can keep track of accounts they've created, and usernames they've used.
Tries to find a derivation path for the stxPrivateKey for the account defined by rootNode and index that respects the username of that account.
The stxPrivateKey is used to sign the profile of the account, therefore, a username must be owned by the stxPrivateKey.
If a username is provided, a lookup for the owner address on the provided network is done.
If no username is provided, a lookup for names owned by the stx derivation path and by the data derivation path is done.
username and derivation type
Generated using TypeDoc
@stacks/wallet-sdk
@stacks/wallet-sdk
is a library for building wallets for the Stacks blockchain.@stacks/transactions
Features
Key Concepts
Secret Key
A Secret Key is a 12 or 24 word mnemonic phrase, which can be used to deterministically generate a wallet and any number of addresses. When the same Secret Key is used, the exact same addresses will be generated. The Secret Key acts as an easily rememberable and highly secure mechanism for backing up a wallet.
Secret Keys conform to the BIP 39 standard.
Wallet
A "wallet" is a set of private keys for an individual user. A wallet will contain any number of accounts.
Account
Accounts act as a way for users to separate assets and data within their own account. You could think of accounts like different Google accounts while logged into Gmail. You can easily switch between different accounts, but they all have different data and information.
Derivation paths
Private keys are generated according to the BIP32 and BIP44 standards.
The "coin type" for the Stacks blockchain is
5757
.The private key for each account's STX address is derived from
m/44'/5757'/0'/0/n
, wheren
is the index of the account.Usage
Installation
With NPM:
With Yarn:
Generate a Secret Key
By default, a random 24-word Secret Key is generated, using 256 bits of entropy. You can generate a random 12-word key by passing
128
as theentropy
argument.Generate a wallet
Create a random Secret Key and a
Wallet
object. When a wallet is generated, the first account is automatically generated as well.A
Wallet
is a normal JavaScript object with the following properties:Generating new accounts
Accounts allow users to use separate Stacks addresses from within the same wallet. Each account has it's own Stacks address and balance. When a user logs into an app, they choose a specific account.
When using
generateNewAccount
, the new account is created with next index, based on the existing accounts in a wallet. For example, if a wallet has 5 accounts, callinggenerateNewAccount
will make the sixth account.An
Account
is a JavaScript object with these properties:Restoring accounts for an existing Wallet
When a user restores their wallet in a new app, you can automatically restore any previously-used accounts from the same wallet. It will also restore any usernames owned by this user.
The private keys used to encrypt this data is derived from the path
m/44/5757'/0'/1
. This data is stored in Gaia, the decentralized storage system in the Stacks network. Users can host their own Gaia hub, and this library's API can use that Gaia hub, if provided.Making an authentication response
With an account, you can generate an authentication response, which conforms to the Stacks authentication protocol. The resulting
authResponse
is a string, representing a signed JSON web token. Learn more about the authentication protocol.Usage with
@stacks/transactions
This library is meant to be used in conjunction with the
@stacks/transactions
library for signing transactions.Getting an account's STX address
Signing Stacks Transactions
You can generate signed transactions by following the documentation from
@stacks/transactions
. Use thestxPrivateKey
of an account as thesenderKey
option when creating a transaction.