Skip to content

Wallet

Source

Encrypted wallet container with a scoped signing capability boundary.

Type Address1111${string} branded type. All address parameters in the SDK expect this type.

Interface SigningCapability:

MethodDescription
signDigest(digest: Uint8Array): Promise<Uint8Array>Signs a raw digest.
getPublicKey(): Uint8ArrayReturns the public key.

The capability is only valid within the withSigningCapability callback scope.

Wallet.fromPrivateKey (static)

ts
Wallet.fromPrivateKey(
  name: string,
  privateKey: Uint8Array,
  password: string,
  masterNodeId?: string | null,
  index?: number | null
): Promise<Wallet>

Creates a new Wallet by encrypting the private key with the provided password.

Parameters:

NameTypeRequiredDescription
namestringYesHuman-readable wallet name.
privateKeyUint8ArrayYessecp256k1 private key (32 bytes).
passwordstringYesPassword used to encrypt the private key.
masterNodeIdstring | nullNoID of the master key node (used for HD wallet tracking).
indexnumber | nullNoBIP-44 derivation index.

Returns: Promise<Wallet> — new wallet instance with encrypted private key.

Wallet.fromEncryptedData (static)

ts
Wallet.fromEncryptedData(
  name: string,
  address: Address,
  encryptedPrivateKey: EncryptedData,
  masterNodeId: string | null,
  index: number | null
): Wallet

Creates a Wallet from pre-encrypted data. Used when restoring a wallet from storage.

Parameters:

NameTypeRequiredDescription
namestringYesWallet name.
addressAddressYesWallet address. Must pass full validateAddress().
encryptedPrivateKeyEncryptedDataYesEncrypted private key object.
masterNodeIdstring | nullYesMaster key ID or null.
indexnumber | nullYesDerivation index or null.

Returns: Wallet — restored wallet instance.

Throws: Error("Invalid address format: ${errorCode}") — if address validation fails.

withSigningCapability

ts
wallet.withSigningCapability<T>(
  password: string,
  callback: (capability: SigningCapability) => Promise<T> | T
): Promise<T>

Grants a scoped signing capability to callback. Decrypts the private key, invokes callback with a SigningCapability object, then zeros the key from memory. The capability cannot be used after the callback returns.

Parameters:

NameTypeRequiredDescription
passwordstringYesPassword to decrypt the private key.
callback(capability: SigningCapability) => Promise<T> | TYesFunction that uses the capability for signing.

Returns: Promise<T> — return value of the callback.

Throws:

  • Error("Unlock Failed: ${errorMessage}") — if decryption fails (wrong password or corrupted data).
  • Error("Signing capability has expired") — if capability is used outside the callback scope.

getEncryptedPrivateKey

ts
getEncryptedPrivateKey(): EncryptedData

Returns the encrypted private key object.

Returns: EncryptedData{ data, salt, iv, version }.

registerAsset

ts
registerAsset(asset: Asset): void

Registers an asset with the wallet.

Parameters:

NameTypeRequiredDescription
assetAssetYesAsset to register.

Other methods

ts
getAddress(): Address           // Returns the wallet's blockchain address
getName(): string               // Returns the wallet's name
getIndex(): number | null       // Returns BIP-44 derivation index, or null
getAssets(): Assets             // Returns Map<AssetId, Asset> of registered assets
isWalletLocked(): boolean       // True if the private key is not in memory
toString(): string              // JSON-encoded StoredWalletMeta (no private key)

ASI:Chain DevNet - Development Network