# keychain | Stacks.js 1.4.1 Library Reference
Documentation for Stacks.js 1.4.1 Library Reference

# @stacks/keychain

Create and manage keys/wallets for the Stacks blockchain.

## Installation

    npm install @stacks/keychain

## Index

### Enumerations

- IdentityNameValidityError
- Subdomains

### Classes

- Identity
- Wallet
- WalletSigner

### Interfaces

- ConfigApp
- ConstructorOptions
- IdentityKeyPair
- Profile
- ProfileImage
- WalletConfig

### Type aliases

- AllowedKeyEntropyBits

### Properties

- default

### Variables

- DEFAULT_PROFILE
- derivationPaths
- registrars

### Functions

- assertIsTruthy
- decrypt
- deriveIdentityKeyPair
- deriveRootKeychainFromMnemonic
- deriveStxAddressChain
- encrypt
- encryptMnemonicFormatted
- fetchProfile
- generateEncryptedMnemonicRootKeychain
- generateMnemonicRootKeychain
- getAddress
- getBitcoinAddressNode
- getBitcoinPrivateKeychain
- getBlockchainIdentities
- getDerivationPath
- getIdentityOwnerAddressNode
- getIdentityPrivateKeychain
- getProfileURLFromZoneFile
- makeIdentity
- recursiveRestoreIdentities
- registerSubdomain
- signAndUploadProfile
- signProfileForUpload
- uploadProfile
- validateSubdomain
- validateSubdomainAvailability
- validateSubdomainFormat

## Type aliases

### AllowedKeyEntropyBits

AllowedKeyEntropyBits: 128 | 256

- Defined in packages/keychain/src/mnemonic/index.ts:8

## Properties

### default

default: { Wallet: typeof Wallet }

#### Type declaration

- ##### Wallet: typeof Wallet

## Variables

### Const DEFAULT_PROFILE

DEFAULT_PROFILE: Profile = ...

- Defined in packages/keychain/src/profiles.ts:35

### Const derivationPaths

derivationPaths: { 1: string; 2147483648: string } = ...

- Defined in packages/keychain/src/address-derivation/index.ts:7

#### Type declaration

- ##### 1: string

- ##### 2147483648: string

### Const registrars

registrars: { id.blockstack: { apiUrl: string; registerUrl: string }; test-personal.id: { apiUrl: string; registerUrl: string } } = ...

- Defined in packages/keychain/src/profiles.ts:47

#### Type declaration

- ##### id.blockstack: { apiUrl: string; registerUrl: string }

  - ##### apiUrl: string

  - ##### registerUrl: string

- ##### test-personal.id: { apiUrl: string; registerUrl: string }

  - ##### apiUrl: string

  - ##### registerUrl: string

## Functions

### assertIsTruthy

- assertIsTruthy<T>(val: any): asserts val is NonNullable<T>

- - Defined in packages/keychain/src/utils/index.ts:150

  #### Type parameters

  - #### T

  #### Parameters

  - ##### val: any

  #### Returns asserts val is NonNullable<T>

### decrypt

- decrypt(dataBuffer: Buffer | string, password: string): Promise<string>

- - Defined in packages/keychain/src/encryption/decrypt.ts:13

  Decrypt an encrypted mnemonic phrase with a password. Legacy triplesec encrypted payloads are also supported.

  #### Parameters

  - ##### dataBuffer: Buffer | string

  - ##### password: string

    Password for data

  #### Returns Promise<string>

  the raw mnemonic phrase

### deriveIdentityKeyPair

- deriveIdentityKeyPair(identityOwnerAddressNode: IdentityAddressOwnerNode): IdentityKeyPair

- - Defined in packages/keychain/src/utils/index.ts:78

  #### Parameters

  - ##### identityOwnerAddressNode: IdentityAddressOwnerNode

  #### Returns IdentityKeyPair

### deriveRootKeychainFromMnemonic

- deriveRootKeychainFromMnemonic(plaintextMnemonic: string): Promise<BIP32Interface>

- - Defined in packages/keychain/src/mnemonic/index.ts:35

  #### Parameters

  - ##### plaintextMnemonic: string

  #### Returns Promise<BIP32Interface>

### deriveStxAddressChain

- deriveStxAddressChain(chain: ChainID ): (rootNode: BIP32Interface) => { address: string; childKey: BIP32Interface; privateKey: string }

- - Defined in packages/keychain/src/address-derivation/index.ts:16

  #### Parameters

  - ##### chain: ChainID

  #### Returns (rootNode: BIP32Interface) => { address: string; childKey: BIP32Interface; privateKey: string }

  - - (rootNode: BIP32Interface): { address: string; childKey: BIP32Interface; privateKey: string }

    - #### Parameters

      - ##### rootNode: BIP32Interface

      #### Returns { address: string; childKey: BIP32Interface; privateKey: string }

      - ##### address: string

      - ##### childKey: BIP32Interface

      - ##### privateKey: string

### encrypt

- encrypt(phrase: string, password: string): Promise<Buffer>

- - Defined in packages/keychain/src/encryption/encrypt.ts:9

  Encrypt a raw mnemonic phrase to be password protected

  #### Parameters

  - ##### phrase: string

    Raw mnemonic phrase

  - ##### password: string

    Password to encrypt mnemonic with

  #### Returns Promise<Buffer>

  The encrypted phrase

### encryptMnemonicFormatted

- encryptMnemonicFormatted(plaintextMnemonic: string, password: string): Promise<{ encryptedMnemonic: Buffer; encryptedMnemonicHex: string }>

- - Defined in packages/keychain/src/mnemonic/index.ts:41

  #### Parameters

  - ##### plaintextMnemonic: string

  - ##### password: string

  #### Returns Promise<{ encryptedMnemonic: Buffer; encryptedMnemonicHex: string }>

### Const fetchProfile

- fetchProfile(__namedParameters: { gaiaUrl: string; identity: Identity }): Promise<null | Profile >

- - Defined in packages/keychain/src/profiles.ts:177

  #### Parameters

  - ##### __namedParameters: { gaiaUrl: string; identity: Identity }

    - ##### gaiaUrl: string

    - ##### identity: Identity

  #### Returns Promise<null | Profile >

### generateEncryptedMnemonicRootKeychain

- generateEncryptedMnemonicRootKeychain(password: string, entropy: AllowedKeyEntropyBits ): Promise<{ encryptedMnemonicPhrase: string; rootNode: BIP32Interface }>

- - Defined in packages/keychain/src/mnemonic/index.ts:20

  #### Parameters

  - ##### password: string

  - ##### entropy: AllowedKeyEntropyBits

  #### Returns Promise<{ encryptedMnemonicPhrase: string; rootNode: BIP32Interface }>

### generateMnemonicRootKeychain

- generateMnemonicRootKeychain(entropy: AllowedKeyEntropyBits ): Promise<{ plaintextMnemonic: string; rootNode: BIP32Interface }>

- - Defined in packages/keychain/src/mnemonic/index.ts:10

  #### Parameters

  - ##### entropy: AllowedKeyEntropyBits

  #### Returns Promise<{ plaintextMnemonic: string; rootNode: BIP32Interface }>

### getAddress

- getAddress(node: BIP32Interface): string

- - Defined in packages/keychain/src/utils/index.ts:65

  #### Parameters

  - ##### node: BIP32Interface

  #### Returns string

### getBitcoinAddressNode

- getBitcoinAddressNode(bitcoinKeychain: BIP32Interface, addressIndex?: number, chainType?: string): BIP32Interface

- - Defined in packages/keychain/src/utils/index.ts:30

  #### Parameters

  - ##### bitcoinKeychain: BIP32Interface

  - ##### addressIndex: number = 0

  - ##### chainType: string = ...

  #### Returns BIP32Interface

### getBitcoinPrivateKeychain

- getBitcoinPrivateKeychain(rootNode: BIP32Interface): BIP32Interface

- - Defined in packages/keychain/src/utils/index.ts:19

  #### Parameters

  - ##### rootNode: BIP32Interface

  #### Returns BIP32Interface

### getBlockchainIdentities

- getBlockchainIdentities(rootNode: BIP32Interface, identitiesToGenerate: number): Promise<{ bitcoinPublicKeychain: string; firstBitcoinAddress: string; identities: Identity []; identityAddresses: string[]; identityKeypairs: IdentityKeyPair []; identityPublicKeychain: string }>

- - Defined in packages/keychain/src/utils/index.ts:97

  #### Parameters

  - ##### rootNode: BIP32Interface

  - ##### identitiesToGenerate: number

  #### Returns Promise<{ bitcoinPublicKeychain: string; firstBitcoinAddress: string; identities: Identity []; identityAddresses: string[]; identityKeypairs: IdentityKeyPair []; identityPublicKeychain: string }>

### getDerivationPath

- getDerivationPath(chain: ChainID ): string

- - Defined in packages/keychain/src/address-derivation/index.ts:12

  #### Parameters

  - ##### chain: ChainID

  #### Returns string

### getIdentityOwnerAddressNode

- getIdentityOwnerAddressNode(identityPrivateKeychain: BIP32Interface, identityIndex?: number): Promise<default>

- - Defined in packages/keychain/src/utils/index.ts:48

  #### Parameters

  - ##### identityPrivateKeychain: BIP32Interface

  - ##### identityIndex: number = 0

  #### Returns Promise<default>

### getIdentityPrivateKeychain

- getIdentityPrivateKeychain(rootNode: BIP32Interface): BIP32Interface

- - Defined in packages/keychain/src/utils/index.ts:12

  #### Parameters

  - ##### rootNode: BIP32Interface

  #### Returns BIP32Interface

### Const getProfileURLFromZoneFile

- getProfileURLFromZoneFile(name: string): Promise<undefined | string>

- - Defined in packages/keychain/src/utils/index.ts:250

  #### Parameters

  - ##### name: string

  #### Returns Promise<undefined | string>

### Const makeIdentity

- makeIdentity(rootNode: BIP32Interface, index: number): Promise< Identity >

- - Defined in packages/keychain/src/utils/index.ts:135

  #### Parameters

  - ##### rootNode: BIP32Interface

  - ##### index: number

  #### Returns Promise< Identity >

### Const recursiveRestoreIdentities

- recursiveRestoreIdentities(__namedParameters: RecursiveMakeIdentitiesOptions): Promise< Identity []>

- - Defined in packages/keychain/src/utils/index.ts:204

  Restore identities by recursively making a new identity, and checking if it has a username.

  As soon as a username is not found for an identity, the recursion stops.

  #### Parameters

  - ##### __namedParameters: RecursiveMakeIdentitiesOptions

  #### Returns Promise< Identity []>

### Const registerSubdomain

- registerSubdomain(__namedParameters: RegisterParams): Promise< Identity >

- - Defined in packages/keychain/src/profiles.ts:140

  Register a subdomain for a given identity

  #### Parameters

  - ##### __namedParameters: RegisterParams

  #### Returns Promise< Identity >

### Const signAndUploadProfile

- signAndUploadProfile(__namedParameters: { gaiaHubConfig?: GaiaHubConfig ; gaiaHubUrl: string; identity: Identity ; profile: Profile }): Promise<void>

- - Defined in packages/keychain/src/profiles.ts:162

  #### Parameters

  - ##### __namedParameters: { gaiaHubConfig?: GaiaHubConfig ; gaiaHubUrl: string; identity: Identity ; profile: Profile }

    - ##### Optional gaiaHubConfig?: GaiaHubConfig

    - ##### gaiaHubUrl: string

    - ##### identity: Identity

    - ##### profile: Profile

  #### Returns Promise<void>

### signProfileForUpload

- signProfileForUpload(profile: Profile, keypair: IdentityKeyPair ): string

- - Defined in packages/keychain/src/profiles.ts:58

  #### Parameters

  - ##### profile: Profile

  - ##### keypair: IdentityKeyPair

  #### Returns string

### uploadProfile

- uploadProfile(gaiaHubUrl: string, identity: Identity, signedProfileTokenData: string, gaiaHubConfig?: GaiaHubConfig ): Promise<string>

- - Defined in packages/keychain/src/profiles.ts:68

  #### Parameters

  - ##### gaiaHubUrl: string

  - ##### identity: Identity

  - ##### signedProfileTokenData: string

  - ##### Optional gaiaHubConfig: GaiaHubConfig

  #### Returns Promise<string>

### Const validateSubdomain

- validateSubdomain(name: string, subdomain?: Subdomains ): Promise<null | IdentityNameValidityError >

- - Defined in packages/keychain/src/utils/index.ts:224

  Validate the format and availability of a subdomain. Will return an error of enum IdentityNameValidityError if an error is present. If no errors are found, will return null.

  #### Parameters

  - ##### name: string

    the subdomain to be registered

  - ##### subdomain: Subdomains = ...

    a valid Subdomains enum

  #### Returns Promise<null | IdentityNameValidityError >

### Const validateSubdomainAvailability

- validateSubdomainAvailability(name: string, subdomain?: Subdomains ): Promise<any>

- - Defined in packages/keychain/src/utils/index.ts:183

  #### Parameters

  - ##### name: string

  - ##### subdomain: Subdomains = ...

  #### Returns Promise<any>

### Const validateSubdomainFormat

- validateSubdomainFormat(identityName: string): null | IdentityNameValidityError

- - Defined in packages/keychain/src/utils/index.ts:165

  #### Parameters

  - ##### identityName: string

  #### Returns null | IdentityNameValidityError

Generated using TypeDoc