@tetherto/wdk-wallet 1.0.0-beta.1 → 1.0.0-beta.11

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/bare.js CHANGED
@@ -13,8 +13,8 @@
13
13
  // limitations under the License.
14
14
  'use strict'
15
15
 
16
- import 'bare-wdk-runtime'
16
+ import 'bare-node-runtime/global'
17
17
 
18
- export * from './index.js' with { imports: 'bare-wdk-runtime/package' }
18
+ export * from './index.js' with { imports: 'bare-node-runtime/imports' }
19
19
 
20
- export { default } from './index.js' with { imports: 'bare-wdk-runtime/package' }
20
+ export { default } from './index.js' with { imports: 'bare-node-runtime/imports' }
package/index.js CHANGED
@@ -25,8 +25,13 @@
25
25
 
26
26
  export { default } from './src/wallet-manager.js'
27
27
 
28
- export { default as WalletAccountReadOnly, IWalletAccountReadOnly } from './src/wallet-account-read-only.js'
28
+ export {
29
+ default as WalletAccountReadOnly,
30
+ IWalletAccountReadOnly
31
+ } from './src/wallet-account-read-only.js'
29
32
 
30
33
  export { IWalletAccount } from './src/wallet-account.js'
31
34
 
32
- export { NotImplementedError } from './src/errors.js'
35
+ export { NotImplementedError, SignerError } from './src/errors.js'
36
+
37
+ export { ISigner } from './src/signer.js'
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@tetherto/wdk-wallet",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.11",
4
4
  "description": "A simple package to manage BIP-32 wallets.",
5
- "keywords": ["wdk", "wallet", "bip-32"],
5
+ "keywords": [
6
+ "wdk",
7
+ "wallet",
8
+ "bip-32"
9
+ ],
6
10
  "author": "Tether",
7
11
  "license": "Apache-2.0",
8
12
  "repository": {
@@ -20,7 +24,7 @@
20
24
  "test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage"
21
25
  },
22
26
  "dependencies": {
23
- "bare-wdk-runtime": "2.0.0",
27
+ "bare-node-runtime": "^1.4.0",
24
28
  "bip39": "3.1.0"
25
29
  },
26
30
  "devDependencies": {
@@ -44,9 +48,14 @@
44
48
  }
45
49
  },
46
50
  "publishConfig": {
47
- "access": "restricted",
51
+ "access": "public",
48
52
  "registry": "https://registry.npmjs.org/"
49
53
  },
54
+ "overrides": {
55
+ "brace-expansion": ">=1.1.13",
56
+ "flatted": ">=3.4.2",
57
+ "picomatch": ">=2.3.2"
58
+ },
50
59
  "standard": {
51
60
  "ignore": [
52
61
  "bare.js",
package/src/errors.js CHANGED
@@ -25,3 +25,16 @@ export class NotImplementedError extends Error {
25
25
  this.name = 'NotImplementedError'
26
26
  }
27
27
  }
28
+
29
+ export class SignerError extends Error {
30
+ /**
31
+ * Create a new signer error.
32
+ *
33
+ * @param {string} message - The error's message.
34
+ */
35
+ constructor (message) {
36
+ super(message)
37
+
38
+ this.name = 'SignerError'
39
+ }
40
+ }
@@ -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,50 @@
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
+
54
+ /** @typedef {import('./swidge-protocol.js').SwidgeStatus} SwidgeStatus */
55
+ /** @typedef {import('./swidge-protocol.js').SwidgeFeeType} SwidgeFeeType */
56
+ /** @typedef {import('./swidge-protocol.js').SwidgeProtocolConfig} SwidgeProtocolConfig */
57
+ /** @typedef {import('./swidge-protocol.js').SwidgeOptions} SwidgeOptions */
58
+ /** @typedef {import('./swidge-protocol.js').SwidgeCommonOptions} SwidgeCommonOptions */
59
+ /** @typedef {import('./swidge-protocol.js').SwidgeExactInOptions} SwidgeExactInOptions */
60
+ /** @typedef {import('./swidge-protocol.js').SwidgeExactOutOptions} SwidgeExactOutOptions */
61
+ /** @typedef {import('./swidge-protocol.js').SwidgeFee} SwidgeFee */
62
+ /** @typedef {import('./swidge-protocol.js').SwidgeTransaction} SwidgeTransaction */
63
+ /** @typedef {import('./swidge-protocol.js').SwidgeQuote} SwidgeQuote */
64
+ /** @typedef {import('./swidge-protocol.js').SwidgeResult} SwidgeResult */
65
+ /** @typedef {import('./swidge-protocol.js').SwidgeStatusOptions} SwidgeStatusOptions */
66
+ /** @typedef {import('./swidge-protocol.js').SwidgeStatusResult} SwidgeStatusResult */
67
+ /** @typedef {import('./swidge-protocol.js').SwidgeSupportedChain} SwidgeSupportedChain */
68
+ /** @typedef {import('./swidge-protocol.js').SwidgeSupportedToken} SwidgeSupportedToken */
69
+ /** @typedef {import('./swidge-protocol.js').SwidgeSupportedTokensOptions} SwidgeSupportedTokensOptions */
70
+
33
71
  export { default as SwapProtocol, ISwapProtocol } from './swap-protocol.js'
34
72
 
35
73
  export { default as BridgeProtocol, IBridgeProtocol } from './bridge-protocol.js'
36
74
 
37
75
  export { default as LendingProtocol, ILendingProtocol } from './lending-protocol.js'
76
+
77
+ export { default as FiatProtocol, IFiatProtocol } from './fiat-protocol.js'
78
+
79
+ export { default as SwidgeProtocol, ISwidgeProtocol } from './swidge-protocol.js'