UNPKG

@tetherto/wdk-wallet

Version:

A simple package to manage BIP-32 wallets.

118 lines (103 loc) 3.35 kB
// Copyright 2024 Tether Operations Limited // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. 'use strict' import { IWalletAccountReadOnly } from './wallet-account-read-only.js' import { NotImplementedError } from './errors.js' /** @typedef {import('./wallet-account-read-only.js').Transaction} Transaction */ /** @typedef {import('./wallet-account-read-only.js').TransactionResult} TransactionResult */ /** @typedef {import('./wallet-account-read-only.js').TransferOptions} TransferOptions */ /** @typedef {import('./wallet-account-read-only.js').TransferResult} TransferResult */ /** * @typedef {Object} KeyPair * @property {Uint8Array} publicKey - The public key. * @property {Uint8Array | null} privateKey - The private key (null if the account has been disposed). */ /** @interface */ export class IWalletAccount extends IWalletAccountReadOnly { /** * The derivation path's index of this account. * * @type {number} */ get index () { throw new NotImplementedError('index') } /** * The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)). * * @type {string} */ get path () { throw new NotImplementedError('path') } /** * The account's key pair. * * @type {KeyPair} */ get keyPair () { throw new NotImplementedError('keyPair') } /** * Signs a message. * * @param {string} message - The message to sign. * @returns {Promise<string>} The message's signature. */ async sign (message) { throw new NotImplementedError('sign(message)') } /** * Verifies a message's signature. * * @param {string} message - The original message. * @param {string} signature - The signature to verify. * @returns {Promise<boolean>} True if the signature is valid. */ async verify (message, signature) { throw new NotImplementedError('verify(message, signature)') } /** * Sends a transaction. * * @param {Transaction} tx - The transaction. * @returns {Promise<TransactionResult>} The transaction's result. */ async sendTransaction (tx) { throw new NotImplementedError('sendTransaction(tx)') } /** * Transfers a token to another address. * * @param {TransferOptions} options - The transfer's options. * @returns {Promise<TransferResult>} The transfer's result. */ async transfer (options) { throw new NotImplementedError('transfer(options)') } /** * Returns a read-only copy of the account. * * @returns {Promise<IWalletAccountReadOnly>} The read-only account. */ async toReadOnlyAccount () { throw new NotImplementedError('toReadOnlyAccount()') } /** * Disposes the wallet account, erasing the private key from the memory. */ dispose () { throw new NotImplementedError('dispose()') } }