@tetherto/wdk-wallet 1.0.0-beta.5 → 1.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md ADDED
@@ -0,0 +1,49 @@
1
+ # Agent Guide
2
+
3
+ This repository is part of the Tether WDK (Wallet Development Kit) ecosystem. It follows strict coding conventions and tooling standards to ensure consistency, reliability, and cross-platform compatibility (Node.js and Bare runtime).
4
+
5
+ ## Project Overview
6
+ - **Architecture:** Modular architecture with clear separation between Core, Wallet managers, and Protocols.
7
+ - **Runtime:** Supports both Node.js and Bare runtime.
8
+
9
+ ## Tech Stack & Tooling
10
+ - **Language:** JavaScript (ES2015+).
11
+ - **Module System:** ES Modules (`"type": "module"` in package.json).
12
+ - **Type Checking:** TypeScript is used purely for generating type declarations (`.d.ts`). The source code remains JavaScript.
13
+ - Command: `npm run build:types`
14
+ - **Linting:** `standard` (JavaScript Standard Style).
15
+ - Command: `npm run lint` / `npm run lint:fix`
16
+ - **Testing:** `jest` (configured with `experimental-vm-modules` for ESM support).
17
+ - Command: `npm test`
18
+ - **Dependencies:** `cross-env` is consistently used for environment variable management in scripts.
19
+
20
+ ## Coding Conventions
21
+ - **File Naming:** Kebab-case (e.g., `wallet-manager.js`).
22
+ - **Class Naming:** PascalCase (e.g., `WdkManager`).
23
+ - **Private Members:** Prefixed with `_` (underscore) and explicitly documented with `@private`.
24
+ - **Imports:** Explicit file extensions are mandatory (e.g., `import ... from './file.js'`).
25
+ - **Copyright:** All source files must include the standard Tether copyright header.
26
+
27
+ ## Documentation (JSDoc)
28
+ Source code must be strictly typed using JSDoc comments to support the `build:types` process.
29
+ - **Types:** Use `@typedef` to define or import types.
30
+ - **Methods:** Use `@param`, `@returns`, `@throws`.
31
+ - **Generics:** Use `@template`.
32
+
33
+ ## Development Workflow
34
+ 1. **Install:** `npm install`
35
+ 2. **Lint:** `npm run lint`
36
+ 3. **Test:** `npm test`
37
+ 4. **Build Types:** `npm run build:types`
38
+
39
+ ## Key Files
40
+ - `index.js`: Main entry point.
41
+ - `bare.js`: Entry point for Bare runtime optimization.
42
+ - `src/`: Core logic.
43
+ - `types/`: Generated type definitions (do not edit manually).
44
+
45
+ ## Repository Specifics
46
+ - **Domain:** Base Abstract Classes.
47
+ - **Role:** Defines the standard interfaces and base classes for all specific blockchain wallet implementations.
48
+ - **Key Classes:** `WalletManager`, `WalletAccount`, `WalletAccountReadOnly`, `Protocol`.
49
+ - **Usage:** Primarily a dependency for other `@tetherto/wdk-wallet-*` packages.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tetherto/wdk-wallet",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.7",
4
4
  "description": "A simple package to manage BIP-32 wallets.",
5
5
  "keywords": ["wdk", "wallet", "bip-32"],
6
6
  "author": "Tether",
@@ -0,0 +1,301 @@
1
+ // Copyright 2024 Tether Operations Limited
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ 'use strict'
15
+
16
+ import { NotImplementedError } from '../errors.js'
17
+
18
+ /** @typedef {import('../wallet-account-read-only.js').IWalletAccountReadOnly} IWalletAccountReadOnly */
19
+
20
+ /** @typedef {import('../wallet-account.js').IWalletAccount} IWalletAccount */
21
+
22
+ /**
23
+ * Standardized status for an on/off-ramp transaction.
24
+ * @typedef {'in_progress' | 'failed' | 'completed'} FiatTransactionStatus
25
+ */
26
+
27
+ /**
28
+ * A protocol-agnostic, standardized object representing the details of an on/off-ramp transaction.
29
+ * @typedef {Object} FiatTransactionDetail
30
+ * @property {FiatTransactionStatus} status - The current status of the transaction.
31
+ * @property {string} cryptoAsset - The provider-specific code of the crypto asset (e.g., 'btc').
32
+ * @property {string} fiatCurrency - The currency's ISO 4217 code (e.g., 'USD').
33
+ */
34
+
35
+ /**
36
+ * A protocol-agnostic, standardized object representing a supported crypto asset.
37
+ * @typedef {Object} SupportedCryptoAsset
38
+ * @property {string} code - Provider-specific asset code for the crypto asset.
39
+ * @property {string} networkCode - The network code for the asset, if applicable (e.g., 'ethereum', 'tron').
40
+ * @property {number} decimals - The on-chain number of decimal places for the asset's base unit (e.g., 18 for ETH).
41
+ * @property {string} [name] - The asset's full name (e.g., 'Bitcoin').
42
+ */
43
+
44
+ /**
45
+ * A protocol-agnostic, standardized object representing a supported fiat currency.
46
+ * @typedef {Object} SupportedFiatCurrency
47
+ * @property {string} code - The currency's ISO 4217 code (e.g., 'USD').
48
+ * @property {number} decimals - The number of decimal places for the currency's smallest unit (e.g., 2 for USD, 0 for JPY).
49
+ * @property {string} [name] - The currency's full name (e.g., 'United States Dollar').
50
+ */
51
+
52
+ /**
53
+ * A protocol-agnostic, standardized object representing a supported country.
54
+ * @typedef {Object} SupportedCountry
55
+ * @property {string} code - The country's ISO 3166-1 alpha-2 or alpha-3 code.
56
+ * @property {boolean} isBuyAllowed - Whether buying is supported in this country.
57
+ * @property {boolean} isSellAllowed - Whether selling is supported in this country.
58
+ * @property {string} [name] - The country's common name.
59
+ */
60
+
61
+ /**
62
+ * @typedef {BuyCommonOptions & (BuyExactCryptoAmountOptions | BuyWithFiatAmountOptions)} BuyOptions
63
+ */
64
+
65
+ /**
66
+ * @typedef {Object} BuyCommonOptions
67
+ * @property {string} cryptoAsset - The provider-specific code of the crypto asset to purchase.
68
+ * @property {string} fiatCurrency - The currency's ISO 4217 code (e.g., 'USD').
69
+ * @property {string} [recipient] - The wallet address to receive the purchased crypto asset. Defaults to the account's address.
70
+ */
71
+
72
+ /**
73
+ * @typedef {Object} BuyExactCryptoAmountOptions
74
+ * @property {number | bigint} cryptoAmount - The amount of crypto asset to buy, in its base unit (e.g., wei for ETH).
75
+ * @property {never} [fiatAmount] - The amount of fiat currency to spend, in its smallest unit (e.g., cents for USD).
76
+ */
77
+
78
+ /**
79
+ * @typedef {Object} BuyWithFiatAmountOptions
80
+ * @property {number | bigint} fiatAmount - The amount of fiat currency to spend, in its smallest unit (e.g., cents for USD).
81
+ * @property {never} [cryptoAmount] - The amount of crypto asset to buy, in its base unit (e.g., wei for ETH).
82
+ */
83
+
84
+ /**
85
+ * @typedef {Object} BuyResult
86
+ * @property {string} buyUrl - The URL for the user to complete the purchase.
87
+ */
88
+
89
+ /**
90
+ * @typedef {SellCommonOptions & (SellExactCryptoAmountOptions | SellForFiatAmountOptions)} SellOptions
91
+ */
92
+
93
+ /**
94
+ * @typedef {Object} SellCommonOptions
95
+ * @property {string} cryptoAsset - The provider-specific code of the crypto asset to sell.
96
+ * @property {string} fiatCurrency - The currency's ISO 4217 code (e.g., 'USD').
97
+ * @property {string} [refundAddress] - The wallet address to receive refunds in case of failure. Defaults to the account's address.
98
+ */
99
+
100
+ /**
101
+ * @typedef {Object} SellExactCryptoAmountOptions
102
+ * @property {number | bigint} cryptoAmount - The amount of crypto asset to sell, in its base unit (e.g., wei for ETH).
103
+ * @property {never} [fiatAmount] - The amount of fiat currency to receive, in its smallest unit (e.g., cents for USD).
104
+ */
105
+
106
+ /**
107
+ * @typedef {Object} SellForFiatAmountOptions
108
+ * @property {number | bigint} fiatAmount - The amount of fiat currency to receive, in its smallest unit (e.g., cents for USD).
109
+ * @property {never} [cryptoAmount] - The amount of crypto asset to sell, in its base unit (e.g., wei for ETH).
110
+ */
111
+
112
+ /**
113
+ * @typedef {Object} SellResult
114
+ * @property {string} sellUrl - The URL for the user to complete the sale.
115
+ */
116
+
117
+ /**
118
+ * A protocol-agnostic, standardized object representing a quote for an on/off-ramp transaction.
119
+ * @typedef {Object} FiatQuote
120
+ * @property {bigint} cryptoAmount - The amount of the crypto asset, in its base unit (e.g., wei).
121
+ * @property {bigint} fiatAmount - The amount of the fiat currency, in its smallest unit (e.g., cents).
122
+ * @property {bigint} fee - The fee charged for the transaction, denominated in the smallest unit of the fiat currency.
123
+ * @property {string} rate - The effective exchange rate, expressed as a string to avoid precision loss (e.g., a rate of "3000.50" for ETH/USD means 1 ETH = 3000.50 USD). Note: This rate applies to the standard units (e.g., ETH and USD).
124
+ */
125
+
126
+ /**
127
+ * @interface
128
+ */
129
+ export class IFiatProtocol {
130
+ /**
131
+ * Gets a quote for a crypto asset purchase.
132
+ * @param {Omit<BuyOptions, 'recipient'>} options - The options for the buy operation.
133
+ * @returns {Promise<FiatQuote>} A quote for the transaction.
134
+ */
135
+ async quoteBuy (options) {
136
+ throw new NotImplementedError('quoteBuy(options)')
137
+ }
138
+
139
+ /**
140
+ * Generates a widget URL for a user to purchase a crypto asset with fiat currency.
141
+ * @param {BuyOptions} options - The options for the buy operation.
142
+ * @returns {Promise<BuyResult>} The operation's result.
143
+ */
144
+ async buy (options) {
145
+ throw new NotImplementedError('buy(options)')
146
+ }
147
+
148
+ /**
149
+ * Gets a quote for a crypto asset sale.
150
+ * @param {Omit<SellOptions, 'refundAddress'>} options - The options for the sell operation.
151
+ * @returns {Promise<FiatQuote>} A quote for the transaction.
152
+ */
153
+ async quoteSell (options) {
154
+ throw new NotImplementedError('quoteSell(options)')
155
+ }
156
+
157
+ /**
158
+ * Generates a widget URL for a user to sell a crypto asset for fiat currency.
159
+ * @param {SellOptions} options - The options for the sell operation.
160
+ * @returns {Promise<SellResult>} The operation's result.
161
+ */
162
+ async sell (options) {
163
+ throw new NotImplementedError('sell(options)')
164
+ }
165
+
166
+ /**
167
+ * Retrieves the details of a specific transaction from the provider.
168
+ * @param {string} txId - The unique identifier of the transaction.
169
+ * @returns {Promise<FiatTransactionDetail>} The transaction details.
170
+ */
171
+ async getTransactionDetail (txId) {
172
+ throw new NotImplementedError('getTransactionDetail(txId)')
173
+ }
174
+
175
+ /**
176
+ * Retrieves a list of supported crypto assets from the provider.
177
+ * @returns {Promise<SupportedCryptoAsset[]>} An array of supported crypto assets.
178
+ */
179
+ async getSupportedCryptoAssets () {
180
+ throw new NotImplementedError('getSupportedCryptoAssets()')
181
+ }
182
+
183
+ /**
184
+ * Retrieves a list of supported fiat currencies from the provider.
185
+ * @returns {Promise<SupportedFiatCurrency[]>} An array of supported fiat currencies.
186
+ */
187
+ async getSupportedFiatCurrencies () {
188
+ throw new NotImplementedError('getSupportedFiatCurrencies()')
189
+ }
190
+
191
+ /**
192
+ * Retrieves a list of supported countries from the provider.
193
+ * @returns {Promise<SupportedCountry[]>} An array of supported countries.
194
+ */
195
+ async getSupportedCountries () {
196
+ throw new NotImplementedError('getSupportedCountries()')
197
+ }
198
+ }
199
+
200
+ /**
201
+ * @abstract
202
+ * @implements {IFiatProtocol}
203
+ */
204
+ export default class FiatProtocol {
205
+ /**
206
+ * Creates a new interface to the protocol without binding it to a wallet account.
207
+ *
208
+ * @overload
209
+ * @param {undefined} [account] - The wallet account to use to interact with the protocol.
210
+ */
211
+ /**
212
+ * Creates a new read-only interface to the protocol.
213
+ *
214
+ * @overload
215
+ * @param {IWalletAccountReadOnly} account - The wallet account to use to interact with the protocol.
216
+ */
217
+ /**
218
+ * Creates a new interface to the protocol.
219
+ *
220
+ * @overload
221
+ * @param {IWalletAccount} account - The wallet account to use to interact with the protocol.
222
+ */
223
+ constructor (account) {
224
+ /**
225
+ * The wallet account to use to interact with the protocol.
226
+ *
227
+ * @protected
228
+ * @type {IWalletAccountReadOnly | IWalletAccount | undefined}
229
+ */
230
+ this._account = account
231
+ }
232
+
233
+ /**
234
+ * Gets a quote for a crypto asset purchase.
235
+ * @param {Omit<BuyOptions, 'recipient'>} options - The options for the buy operation.
236
+ * @returns {Promise<FiatQuote>} A quote for the transaction.
237
+ */
238
+ async quoteBuy (options) {
239
+ throw new NotImplementedError('quoteBuy(options)')
240
+ }
241
+
242
+ /**
243
+ * Generates a URL for a user to purchase a crypto asset with fiat currency.
244
+ * @param {BuyOptions} options - The options for the buy operation.
245
+ * @returns {Promise<BuyResult>} The URL for the user to complete the purchase.
246
+ */
247
+ async buy (options) {
248
+ throw new NotImplementedError('buy(options)')
249
+ }
250
+
251
+ /**
252
+ * Gets a quote for a crypto asset sale.
253
+ * @param {Omit<SellOptions, 'refundAddress'>} options - The options for the sell operation.
254
+ * @returns {Promise<FiatQuote>} A quote for the transaction.
255
+ */
256
+ async quoteSell (options) {
257
+ throw new NotImplementedError('quoteSell(options)')
258
+ }
259
+
260
+ /**
261
+ * Generates a URL for a user to sell a crypto asset for fiat currency.
262
+ * @param {SellOptions} options - The options for the sell operation.
263
+ * @returns {Promise<SellResult>} The URL for the user to complete the sale.
264
+ */
265
+ async sell (options) {
266
+ throw new NotImplementedError('sell(options)')
267
+ }
268
+
269
+ /**
270
+ * Retrieves the details of a specific transaction from the provider.
271
+ * @param {string} txId - The unique identifier of the transaction.
272
+ * @returns {Promise<FiatTransactionDetail>} The transaction details.
273
+ */
274
+ async getTransactionDetail (txId) {
275
+ throw new NotImplementedError('getTransactionDetail(txId)')
276
+ }
277
+
278
+ /**
279
+ * Retrieves a list of supported crypto assets from the provider.
280
+ * @returns {Promise<SupportedCryptoAsset[]>} An array of supported crypto assets.
281
+ */
282
+ async getSupportedCryptoAssets () {
283
+ throw new NotImplementedError('getSupportedCryptoAssets()')
284
+ }
285
+
286
+ /**
287
+ * Retrieves a list of supported fiat currencies from the provider.
288
+ * @returns {Promise<SupportedFiatCurrency[]>} An array of supported fiat currencies.
289
+ */
290
+ async getSupportedFiatCurrencies () {
291
+ throw new NotImplementedError('getSupportedFiatCurrencies()')
292
+ }
293
+
294
+ /**
295
+ * Retrieves a list of supported countries or regions from the provider.
296
+ * @returns {Promise<SupportedCountry[]>} An array of supported countries.
297
+ */
298
+ async getSupportedCountries () {
299
+ throw new NotImplementedError('getSupportedCountries()')
300
+ }
301
+ }
@@ -30,8 +30,31 @@
30
30
  /** @typedef {import('./lending-protocol.js').RepayOptions} RepayOptions */
31
31
  /** @typedef {import('./lending-protocol.js').RepayResult} RepayResult */
32
32
 
33
+ /** @typedef {import('./fiat-protocol.js').BuyOptions} BuyOptions */
34
+ /** @typedef {import('./fiat-protocol.js').BuyCommonOptions} BuyCommonOptions */
35
+ /** @typedef {import('./fiat-protocol.js').BuyExactCryptoAmountOptions} BuyExactCryptoAmountOptions */
36
+ /** @typedef {import('./fiat-protocol.js').BuyWithFiatAmountOptions} BuyWithFiatAmountOptions */
37
+ /** @typedef {import('./fiat-protocol.js').BuyResult} BuyResult */
38
+
39
+ /** @typedef {import('./fiat-protocol.js').SellOptions} SellOptions */
40
+ /** @typedef {import('./fiat-protocol.js').SellCommonOptions} SellCommonOptions */
41
+ /** @typedef {import('./fiat-protocol.js').SellExactCryptoAmountOptions} SellExactCryptoAmountOptions */
42
+ /** @typedef {import('./fiat-protocol.js').SellForFiatAmountOptions} SellForFiatAmountOptions */
43
+ /** @typedef {import('./fiat-protocol.js').SellResult} SellResult */
44
+
45
+ /** @typedef {import('./fiat-protocol.js').FiatQuote} FiatQuote */
46
+
47
+ /** @typedef {import('./fiat-protocol.js').FiatTransactionStatus} FiatTransactionStatus */
48
+ /** @typedef {import('./fiat-protocol.js').FiatTransactionDetail} FiatTransactionDetail */
49
+
50
+ /** @typedef {import('./fiat-protocol.js').SupportedCryptoAsset} SupportedCryptoAsset */
51
+ /** @typedef {import('./fiat-protocol.js').SupportedFiatCurrency} SupportedFiatCurrency */
52
+ /** @typedef {import('./fiat-protocol.js').SupportedCountry} SupportedCountry */
53
+
33
54
  export { default as SwapProtocol, ISwapProtocol } from './swap-protocol.js'
34
55
 
35
56
  export { default as BridgeProtocol, IBridgeProtocol } from './bridge-protocol.js'
36
57
 
37
58
  export { default as LendingProtocol, ILendingProtocol } from './lending-protocol.js'
59
+
60
+ export { default as FiatProtocol, IFiatProtocol } from './fiat-protocol.js'
@@ -51,6 +51,18 @@ export class IWalletAccountReadOnly {
51
51
  throw new NotImplementedError('getAddress()')
52
52
  }
53
53
 
54
+ /**
55
+ * Verifies a message's signature.
56
+ *
57
+ * @param {string} message - The original message.
58
+ * @param {string} signature - The signature to verify.
59
+ * @returns {Promise<boolean>} True if the signature is valid.
60
+ * @throws {Error} If the read-only wallet account class is not able to provide an implementation for the method.
61
+ */
62
+ async verify (message, signature) {
63
+ throw new NotImplementedError('verify(message, signature)')
64
+ }
65
+
54
66
  /**
55
67
  * Returns the account's native token balance.
56
68
  *
@@ -139,6 +151,19 @@ export default class WalletAccountReadOnly {
139
151
  return this._address
140
152
  }
141
153
 
154
+ /**
155
+ * Verifies a message's signature.
156
+ *
157
+ * @abstract
158
+ * @param {string} message - The original message.
159
+ * @param {string} signature - The signature to verify.
160
+ * @returns {Promise<boolean>} True if the signature is valid.
161
+ * @throws {Error} If the read-only wallet account class is not able to provide an implementation for the method.
162
+ */
163
+ async verify (message, signature) {
164
+ throw new NotImplementedError('verify(message, signature)')
165
+ }
166
+
142
167
  /**
143
168
  * Returns the account's native token balance.
144
169
  *
@@ -72,10 +72,12 @@ export default class WalletManager {
72
72
  /**
73
73
  * Returns a random [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
74
74
  *
75
+ * @param {12 | 24} [wordCount=12] - The number of words in the seed phrase.
75
76
  * @returns {string} The seed phrase.
76
77
  */
77
- static getRandomSeedPhrase () {
78
- return bip39.generateMnemonic()
78
+ static getRandomSeedPhrase (wordCount = 12) {
79
+ const strength = wordCount === 24 ? 256 : 128
80
+ return bip39.generateMnemonic(strength)
79
81
  }
80
82
 
81
83
  /**
@@ -0,0 +1,315 @@
1
+ /**
2
+ * @interface
3
+ */
4
+ export interface IFiatProtocol {
5
+ /**
6
+ * Gets a quote for a crypto asset purchase.
7
+ * @param {Omit<BuyOptions, 'recipient'>} options - The options for the buy operation.
8
+ * @returns {Promise<FiatQuote>} A quote for the transaction.
9
+ */
10
+ quoteBuy(options: Omit<BuyOptions, "recipient">): Promise<FiatQuote>;
11
+ /**
12
+ * Generates a widget URL for a user to purchase a crypto asset with fiat currency.
13
+ * @param {BuyOptions} options - The options for the buy operation.
14
+ * @returns {Promise<BuyResult>} The operation's result.
15
+ */
16
+ buy(options: BuyOptions): Promise<BuyResult>;
17
+ /**
18
+ * Gets a quote for a crypto asset sale.
19
+ * @param {Omit<SellOptions, 'refundAddress'>} options - The options for the sell operation.
20
+ * @returns {Promise<FiatQuote>} A quote for the transaction.
21
+ */
22
+ quoteSell(options: Omit<SellOptions, "refundAddress">): Promise<FiatQuote>;
23
+ /**
24
+ * Generates a widget URL for a user to sell a crypto asset for fiat currency.
25
+ * @param {SellOptions} options - The options for the sell operation.
26
+ * @returns {Promise<SellResult>} The operation's result.
27
+ */
28
+ sell(options: SellOptions): Promise<SellResult>;
29
+ /**
30
+ * Retrieves the details of a specific transaction from the provider.
31
+ * @param {string} txId - The unique identifier of the transaction.
32
+ * @returns {Promise<FiatTransactionDetail>} The transaction details.
33
+ */
34
+ getTransactionDetail(txId: string): Promise<FiatTransactionDetail>;
35
+ /**
36
+ * Retrieves a list of supported crypto assets from the provider.
37
+ * @returns {Promise<SupportedCryptoAsset[]>} An array of supported crypto assets.
38
+ */
39
+ getSupportedCryptoAssets(): Promise<SupportedCryptoAsset[]>;
40
+ /**
41
+ * Retrieves a list of supported fiat currencies from the provider.
42
+ * @returns {Promise<SupportedFiatCurrency[]>} An array of supported fiat currencies.
43
+ */
44
+ getSupportedFiatCurrencies(): Promise<SupportedFiatCurrency[]>;
45
+ /**
46
+ * Retrieves a list of supported countries from the provider.
47
+ * @returns {Promise<SupportedCountry[]>} An array of supported countries.
48
+ */
49
+ getSupportedCountries(): Promise<SupportedCountry[]>;
50
+ }
51
+ /**
52
+ * @abstract
53
+ * @implements {IFiatProtocol}
54
+ */
55
+ export default abstract class FiatProtocol implements IFiatProtocol {
56
+ /**
57
+ * Creates a new fiat protocol with read-only account.
58
+ *
59
+ * @overload
60
+ * @param {IWalletAccountReadOnly} [account] - The wallet account to use to interact with the protocol.
61
+ */
62
+ constructor(account?: IWalletAccountReadOnly);
63
+ /**
64
+ * Creates a new fiat protocol with read-only account.
65
+ *
66
+ * @overload
67
+ * @param {IWalletAccount} [account] - The wallet account to use to interact with the protocol.
68
+ */
69
+ constructor(account?: IWalletAccount);
70
+ /**
71
+ * The wallet account to use to interact with the protocol.
72
+ *
73
+ * @protected
74
+ * @type {IWalletAccountReadOnly | IWalletAccount | undefined}
75
+ */
76
+ protected _account: IWalletAccountReadOnly | IWalletAccount | undefined;
77
+ /**
78
+ * Gets a quote for a crypto asset purchase.
79
+ * @abstract
80
+ * @param {Omit<BuyOptions, 'recipient'>} options - The options for the buy operation.
81
+ * @returns {Promise<FiatQuote>} A quote for the transaction.
82
+ */
83
+ abstract quoteBuy(options: Omit<BuyOptions, "recipient">): Promise<FiatQuote>;
84
+ /**
85
+ * Generates a URL for a user to purchase a crypto asset with fiat currency.
86
+ * @abstract
87
+ * @param {BuyOptions} options - The options for the buy operation.
88
+ * @returns {Promise<BuyResult>} The URL for the user to complete the purchase.
89
+ */
90
+ abstract buy(options: BuyOptions): Promise<BuyResult>;
91
+ /**
92
+ * Gets a quote for a crypto asset sale.
93
+ * @abstract
94
+ * @param {Omit<SellOptions, 'refundAddress'>} options - The options for the sell operation.
95
+ * @returns {Promise<FiatQuote>} A quote for the transaction.
96
+ */
97
+ abstract quoteSell(options: Omit<SellOptions, "refundAddress">): Promise<FiatQuote>;
98
+ /**
99
+ * Generates a URL for a user to sell a crypto asset for fiat currency.
100
+ * @abstract
101
+ * @param {SellOptions} options - The options for the sell operation.
102
+ * @returns {Promise<SellResult>} The URL for the user to complete the sale.
103
+ */
104
+ abstract sell(options: SellOptions): Promise<SellResult>;
105
+ /**
106
+ * Retrieves the details of a specific transaction from the provider.
107
+ * @abstract
108
+ * @param {string} txId - The unique identifier of the transaction.
109
+ * @returns {Promise<FiatTransactionDetail>} The transaction details.
110
+ */
111
+ abstract getTransactionDetail(txId: string): Promise<FiatTransactionDetail>;
112
+ /**
113
+ * Retrieves a list of supported crypto assets from the provider.
114
+ * @abstract
115
+ * @returns {Promise<SupportedCryptoAsset[]>} An array of supported crypto assets.
116
+ */
117
+ abstract getSupportedCryptoAssets(): Promise<SupportedCryptoAsset[]>;
118
+ /**
119
+ * Retrieves a list of supported fiat currencies from the provider.
120
+ * @abstract
121
+ * @returns {Promise<SupportedFiatCurrency[]>} An array of supported fiat currencies.
122
+ */
123
+ abstract getSupportedFiatCurrencies(): Promise<SupportedFiatCurrency[]>;
124
+ /**
125
+ * Retrieves a list of supported countries or regions from the provider.
126
+ * @abstract
127
+ * @returns {Promise<SupportedCountry[]>} An array of supported countries.
128
+ */
129
+ abstract getSupportedCountries(): Promise<SupportedCountry[]>;
130
+ }
131
+ export type IWalletAccountReadOnly = import("../wallet-account-read-only.js").IWalletAccountReadOnly;
132
+ export type IWalletAccount = import("../wallet-account.js").IWalletAccount;
133
+ /**
134
+ * Standardized status for an on/off-ramp transaction.
135
+ */
136
+ export type FiatTransactionStatus = "in_progress" | "failed" | "completed";
137
+ /**
138
+ * A protocol-agnostic, standardized object representing the details of an on/off-ramp transaction.
139
+ */
140
+ export type FiatTransactionDetail = {
141
+ /**
142
+ * - The current status of the transaction.
143
+ */
144
+ status: FiatTransactionStatus;
145
+ /**
146
+ * - The provider-specific code of the crypto asset (e.g., 'btc').
147
+ */
148
+ cryptoAsset: string;
149
+ /**
150
+ * - The currency's ISO 4217 code (e.g., 'USD').
151
+ */
152
+ fiatCurrency: string;
153
+ };
154
+ /**
155
+ * A protocol-agnostic, standardized object representing a supported crypto asset.
156
+ */
157
+ export type SupportedCryptoAsset = {
158
+ /**
159
+ * - Provider-specific asset code for the crypto asset.
160
+ */
161
+ code: string;
162
+ /**
163
+ * - The network code for the asset, if applicable (e.g., 'ethereum', 'tron').
164
+ */
165
+ networkCode: string;
166
+ /**
167
+ * - The on-chain number of decimal places for the asset's base unit (e.g., 18 for ETH).
168
+ */
169
+ decimals: number;
170
+ /**
171
+ * - The asset's full name (e.g., 'Bitcoin').
172
+ */
173
+ name?: string;
174
+ };
175
+ /**
176
+ * A protocol-agnostic, standardized object representing a supported fiat currency.
177
+ */
178
+ export type SupportedFiatCurrency = {
179
+ /**
180
+ * - The currency's ISO 4217 code (e.g., 'USD').
181
+ */
182
+ code: string;
183
+ /**
184
+ * - The number of decimal places for the currency's smallest unit (e.g., 2 for USD, 0 for JPY).
185
+ */
186
+ decimals: number;
187
+ /**
188
+ * - The currency's full name (e.g., 'United States Dollar').
189
+ */
190
+ name?: string;
191
+ };
192
+ /**
193
+ * A protocol-agnostic, standardized object representing a supported country.
194
+ */
195
+ export type SupportedCountry = {
196
+ /**
197
+ * - The country's ISO 3166-1 alpha-2 or alpha-3 code.
198
+ */
199
+ code: string;
200
+ /**
201
+ * - Whether buying is supported in this country.
202
+ */
203
+ isBuyAllowed: boolean;
204
+ /**
205
+ * - Whether selling is supported in this country.
206
+ */
207
+ isSellAllowed: boolean;
208
+ /**
209
+ * - The country's common name.
210
+ */
211
+ name?: string;
212
+ };
213
+ export type BuyOptions = BuyCommonOptions & (BuyExactCryptoAmountOptions | BuyWithFiatAmountOptions);
214
+ export type BuyCommonOptions = {
215
+ /**
216
+ * - The provider-specific code of the crypto asset to purchase.
217
+ */
218
+ cryptoAsset: string;
219
+ /**
220
+ * - The currency's ISO 4217 code (e.g., 'USD').
221
+ */
222
+ fiatCurrency: string;
223
+ /**
224
+ * - The wallet address to receive the purchased crypto asset. Defaults to the account's address.
225
+ */
226
+ recipient?: string;
227
+ };
228
+ export type BuyExactCryptoAmountOptions = {
229
+ /**
230
+ * - The amount of crypto asset to buy, in its base unit (e.g., wei for ETH).
231
+ */
232
+ cryptoAmount: number | bigint;
233
+ /**
234
+ * - The amount of fiat currency to spend, in its smallest unit (e.g., cents for USD).
235
+ */
236
+ fiatAmount?: never;
237
+ };
238
+ export type BuyWithFiatAmountOptions = {
239
+ /**
240
+ * - The amount of fiat currency to spend, in its smallest unit (e.g., cents for USD).
241
+ */
242
+ fiatAmount: number | bigint;
243
+ /**
244
+ * - The amount of crypto asset to buy, in its base unit (e.g., wei for ETH).
245
+ */
246
+ cryptoAmount?: never;
247
+ };
248
+ export type BuyResult = {
249
+ /**
250
+ * - The URL for the user to complete the purchase.
251
+ */
252
+ buyUrl: string;
253
+ };
254
+ export type SellOptions = SellCommonOptions & (SellExactCryptoAmountOptions | SellForFiatAmountOptions);
255
+ export type SellCommonOptions = {
256
+ /**
257
+ * - The provider-specific code of the crypto asset to sell.
258
+ */
259
+ cryptoAsset: string;
260
+ /**
261
+ * - The currency's ISO 4217 code (e.g., 'USD').
262
+ */
263
+ fiatCurrency: string;
264
+ /**
265
+ * - The wallet address to receive refunds in case of failure. Defaults to the account's address.
266
+ */
267
+ refundAddress?: string;
268
+ };
269
+ export type SellExactCryptoAmountOptions = {
270
+ /**
271
+ * - The amount of crypto asset to sell, in its base unit (e.g., wei for ETH).
272
+ */
273
+ cryptoAmount: number | bigint;
274
+ /**
275
+ * - The amount of fiat currency to receive, in its smallest unit (e.g., cents for USD).
276
+ */
277
+ fiatAmount?: never;
278
+ };
279
+ export type SellForFiatAmountOptions = {
280
+ /**
281
+ * - The amount of fiat currency to receive, in its smallest unit (e.g., cents for USD).
282
+ */
283
+ fiatAmount: number | bigint;
284
+ /**
285
+ * - The amount of crypto asset to sell, in its base unit (e.g., wei for ETH).
286
+ */
287
+ cryptoAmount?: never;
288
+ };
289
+ export type SellResult = {
290
+ /**
291
+ * - The URL for the user to complete the sale.
292
+ */
293
+ sellUrl: string;
294
+ };
295
+ /**
296
+ * A protocol-agnostic, standardized object representing a quote for an on/off-ramp transaction.
297
+ */
298
+ export type FiatQuote = {
299
+ /**
300
+ * - The amount of the crypto asset, in its base unit (e.g., wei).
301
+ */
302
+ cryptoAmount: bigint;
303
+ /**
304
+ * - The amount of the fiat currency, in its smallest unit (e.g., cents).
305
+ */
306
+ fiatAmount: bigint;
307
+ /**
308
+ * - The fee charged for the transaction, denominated in the smallest unit of the fiat currency.
309
+ */
310
+ fee: bigint;
311
+ /**
312
+ * - The effective exchange rate, expressed as a string to avoid precision loss (e.g., a rate of "3000.50" for ETH/USD means 1 ETH = 3000.50 USD). Note: This rate applies to the standard units (e.g., ETH and USD).
313
+ */
314
+ rate: string;
315
+ };
@@ -12,6 +12,23 @@ export type BorrowOptions = import("./lending-protocol.js").BorrowOptions;
12
12
  export type BorrowResult = import("./lending-protocol.js").BorrowResult;
13
13
  export type RepayOptions = import("./lending-protocol.js").RepayOptions;
14
14
  export type RepayResult = import("./lending-protocol.js").RepayResult;
15
+ export type BuyOptions = import("./fiat-protocol.js").BuyOptions;
16
+ export type BuyCommonOptions = import("./fiat-protocol.js").BuyCommonOptions;
17
+ export type BuyExactCryptoAmountOptions = import("./fiat-protocol.js").BuyExactCryptoAmountOptions;
18
+ export type BuyWithFiatAmountOptions = import("./fiat-protocol.js").BuyWithFiatAmountOptions;
19
+ export type BuyResult = import("./fiat-protocol.js").BuyResult;
20
+ export type SellOptions = import("./fiat-protocol.js").SellOptions;
21
+ export type SellCommonOptions = import("./fiat-protocol.js").SellCommonOptions;
22
+ export type SellExactCryptoAmountOptions = import("./fiat-protocol.js").SellExactCryptoAmountOptions;
23
+ export type SellForFiatAmountOptions = import("./fiat-protocol.js").SellForFiatAmountOptions;
24
+ export type SellResult = import("./fiat-protocol.js").SellResult;
25
+ export type FiatQuote = import("./fiat-protocol.js").FiatQuote;
26
+ export type FiatTransactionStatus = import("./fiat-protocol.js").FiatTransactionStatus;
27
+ export type FiatTransactionDetail = import("./fiat-protocol.js").FiatTransactionDetail;
28
+ export type SupportedCryptoAsset = import("./fiat-protocol.js").SupportedCryptoAsset;
29
+ export type SupportedFiatCurrency = import("./fiat-protocol.js").SupportedFiatCurrency;
30
+ export type SupportedCountry = import("./fiat-protocol.js").SupportedCountry;
15
31
  export { default as SwapProtocol, ISwapProtocol } from "./swap-protocol.js";
16
32
  export { default as BridgeProtocol, IBridgeProtocol } from "./bridge-protocol.js";
17
33
  export { default as LendingProtocol, ILendingProtocol } from "./lending-protocol.js";
34
+ export { default as FiatProtocol, IFiatProtocol } from "./fiat-protocol.js";
@@ -6,6 +6,15 @@ export interface IWalletAccountReadOnly {
6
6
  * @returns {Promise<string>} The account's address.
7
7
  */
8
8
  getAddress(): Promise<string>;
9
+ /**
10
+ * Verifies a message's signature.
11
+ *
12
+ * @param {string} message - The original message.
13
+ * @param {string} signature - The signature to verify.
14
+ * @returns {Promise<boolean>} True if the signature is valid.
15
+ * @throws {Error} If the read-only wallet account class is not able to provide an implementation for the method.
16
+ */
17
+ verify(message: string, signature: string): Promise<boolean>;
9
18
  /**
10
19
  * Returns the account's native token balance.
11
20
  *
@@ -67,6 +76,16 @@ export default abstract class WalletAccountReadOnly implements IWalletAccountRea
67
76
  * @returns {Promise<string>} The account's address.
68
77
  */
69
78
  getAddress(): Promise<string>;
79
+ /**
80
+ * Verifies a message's signature.
81
+ *
82
+ * @abstract
83
+ * @param {string} message - The original message.
84
+ * @param {string} signature - The signature to verify.
85
+ * @returns {Promise<boolean>} True if the signature is valid.
86
+ * @throws {Error} If the read-only wallet account class is not able to provide an implementation for the method.
87
+ */
88
+ abstract verify(message: string, signature: string): Promise<boolean>;
70
89
  /**
71
90
  * Returns the account's native token balance.
72
91
  *
@@ -3,9 +3,10 @@ export default abstract class WalletManager {
3
3
  /**
4
4
  * Returns a random [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
5
5
  *
6
+ * @param {12 | 24} [wordCount=12] - The number of words in the seed phrase.
6
7
  * @returns {string} The seed phrase.
7
8
  */
8
- static getRandomSeedPhrase(): string;
9
+ static getRandomSeedPhrase(wordCount?: 12 | 24): string;
9
10
  /**
10
11
  * Checks if a seed phrase is valid.
11
12
  *