@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 +49 -0
- package/bare.js +3 -3
- package/index.js +7 -2
- package/package.json +13 -4
- package/src/errors.js +13 -0
- package/src/protocols/fiat-protocol.js +301 -0
- package/src/protocols/index.js +42 -0
- package/src/protocols/swidge-protocol.js +402 -0
- package/src/signer.js +62 -0
- package/src/wallet-account-read-only.js +25 -0
- package/src/wallet-account.js +10 -0
- package/src/wallet-manager.js +135 -22
- package/types/index.d.ts +2 -1
- package/types/src/errors.d.ts +8 -0
- package/types/src/protocols/fiat-protocol.d.ts +315 -0
- package/types/src/protocols/index.d.ts +34 -0
- package/types/src/protocols/swidge-protocol.d.ts +400 -0
- package/types/src/signer.d.ts +34 -0
- package/types/src/wallet-account-read-only.d.ts +19 -0
- package/types/src/wallet-account.d.ts +7 -0
- package/types/src/wallet-manager.d.ts +101 -16
package/src/wallet-manager.js
CHANGED
|
@@ -18,10 +18,12 @@ import * as bip39 from 'bip39'
|
|
|
18
18
|
import { NotImplementedError } from './errors.js'
|
|
19
19
|
|
|
20
20
|
/** @typedef {import('./wallet-account.js').IWalletAccount} IWalletAccount */
|
|
21
|
+
/** @typedef {import('./signer.js').ISigner} ISigner */
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* @typedef {Object} WalletConfig
|
|
24
25
|
* @property {number | bigint} [transferMaxFee] - The maximum fee amount for transfer operations.
|
|
26
|
+
* @property {number | bigint} [transactionMaxFee] - The maximum fee amount for sendTransaction and signTransaction operations.
|
|
25
27
|
*/
|
|
26
28
|
|
|
27
29
|
/**
|
|
@@ -33,30 +35,49 @@ import { NotImplementedError } from './errors.js'
|
|
|
33
35
|
/** @abstract */
|
|
34
36
|
export default class WalletManager {
|
|
35
37
|
/**
|
|
36
|
-
* Creates a new wallet manager.
|
|
38
|
+
* Creates a new wallet manager from a BIP-39 seed.
|
|
37
39
|
*
|
|
38
|
-
* @
|
|
40
|
+
* @overload
|
|
41
|
+
* @param {string | Uint8Array} seed - The BIP-39 seed phrase or raw seed bytes.
|
|
39
42
|
* @param {WalletConfig} [config] - The wallet configuration.
|
|
40
43
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new wallet manager from a default signer.
|
|
47
|
+
*
|
|
48
|
+
* @overload
|
|
49
|
+
* @param {ISigner} signer - The default signer.
|
|
50
|
+
* @param {WalletConfig} [config] - The wallet configuration.
|
|
51
|
+
*/
|
|
52
|
+
constructor (seedOrSigner, config = {}) {
|
|
53
|
+
if (typeof seedOrSigner === 'string') {
|
|
54
|
+
if (!WalletManager.isValidSeedPhrase(seedOrSigner)) {
|
|
44
55
|
throw new Error('The seed phrase is invalid.')
|
|
45
56
|
}
|
|
46
57
|
|
|
47
|
-
|
|
58
|
+
seedOrSigner = bip39.mnemonicToSeedSync(seedOrSigner)
|
|
48
59
|
}
|
|
49
60
|
|
|
61
|
+
const isSeed = seedOrSigner instanceof Uint8Array
|
|
62
|
+
|
|
50
63
|
/** @private */
|
|
51
|
-
this._seed =
|
|
64
|
+
this._seed = isSeed ? seedOrSigner : undefined
|
|
52
65
|
|
|
53
66
|
/**
|
|
54
|
-
* The
|
|
67
|
+
* The default signer.
|
|
55
68
|
*
|
|
56
69
|
* @protected
|
|
57
|
-
* @type {
|
|
70
|
+
* @type {ISigner | undefined}
|
|
58
71
|
*/
|
|
59
|
-
this.
|
|
72
|
+
this._defaultSigner = isSeed ? undefined : seedOrSigner
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A map between signer names and signers added via {@link addSigner}.
|
|
76
|
+
*
|
|
77
|
+
* @protected
|
|
78
|
+
* @type {Record<string, ISigner>}
|
|
79
|
+
*/
|
|
80
|
+
this._signers = {}
|
|
60
81
|
|
|
61
82
|
/**
|
|
62
83
|
* A map between derivation paths and wallet accounts. The {@link dispose} method will automatically dispose
|
|
@@ -64,18 +85,28 @@ export default class WalletManager {
|
|
|
64
85
|
* {@link getAccount} and {@link getAccountByPath} methods.
|
|
65
86
|
*
|
|
66
87
|
* @protected
|
|
67
|
-
* @type {
|
|
88
|
+
* @type {Record<string, IWalletAccount>}
|
|
68
89
|
*/
|
|
69
90
|
this._accounts = {}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The wallet configuration.
|
|
94
|
+
*
|
|
95
|
+
* @protected
|
|
96
|
+
* @type {WalletConfig}
|
|
97
|
+
*/
|
|
98
|
+
this._config = config
|
|
70
99
|
}
|
|
71
100
|
|
|
72
101
|
/**
|
|
73
102
|
* Returns a random [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
|
|
74
103
|
*
|
|
104
|
+
* @param {12 | 24} [wordCount=12] - The number of words in the seed phrase.
|
|
75
105
|
* @returns {string} The seed phrase.
|
|
76
106
|
*/
|
|
77
|
-
static getRandomSeedPhrase () {
|
|
78
|
-
|
|
107
|
+
static getRandomSeedPhrase (wordCount = 12) {
|
|
108
|
+
const strength = wordCount === 24 ? 256 : 128
|
|
109
|
+
return bip39.generateMnemonic(strength)
|
|
79
110
|
}
|
|
80
111
|
|
|
81
112
|
/**
|
|
@@ -89,23 +120,93 @@ export default class WalletManager {
|
|
|
89
120
|
}
|
|
90
121
|
|
|
91
122
|
/**
|
|
92
|
-
* The seed
|
|
123
|
+
* The seed of the wallet.
|
|
93
124
|
*
|
|
94
|
-
* @type {Uint8Array}
|
|
125
|
+
* @type {Uint8Array | undefined}
|
|
95
126
|
*/
|
|
96
127
|
get seed () {
|
|
97
128
|
return this._seed
|
|
98
129
|
}
|
|
99
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Registers a signer under the given name.
|
|
133
|
+
*
|
|
134
|
+
* @param {string} signerName - The signer name.
|
|
135
|
+
* @param {ISigner} signer - The signer.
|
|
136
|
+
* @returns {WalletManager} The wallet manager.
|
|
137
|
+
* @throws {Error} If `signerName` is an empty or blank string.
|
|
138
|
+
*/
|
|
139
|
+
addSigner (signerName, signer) {
|
|
140
|
+
if (!signerName.trim()) {
|
|
141
|
+
throw new Error('The signer name cannot be an empty or blank string.')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
this._signers[signerName] = signer
|
|
145
|
+
return this
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Returns a signer. With no arguments, returns the default signer provided
|
|
150
|
+
* at construction. With a name, returns the signer registered under that
|
|
151
|
+
* name via {@link addSigner}.
|
|
152
|
+
*
|
|
153
|
+
* @param {string} [signerName] - The signer name. Omit to get the default.
|
|
154
|
+
* @returns {ISigner} The signer.
|
|
155
|
+
* @throws {Error} If called with no arguments and no default signer was
|
|
156
|
+
* provided at construction, or if called with a name that is not registered.
|
|
157
|
+
*/
|
|
158
|
+
getSigner (signerName) {
|
|
159
|
+
if (signerName === undefined) {
|
|
160
|
+
if (this._defaultSigner === undefined) {
|
|
161
|
+
throw new Error('No default signer registered.')
|
|
162
|
+
}
|
|
163
|
+
return this._defaultSigner
|
|
164
|
+
}
|
|
165
|
+
const signer = this._signers[signerName]
|
|
166
|
+
if (signer === undefined) {
|
|
167
|
+
throw new Error(`No signer registered with name "${signerName}".`)
|
|
168
|
+
}
|
|
169
|
+
return signer
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Returns a shallow copy of the map of signers registered via {@link addSigner}.
|
|
174
|
+
* The default signer is not included; use {@link getSigner} with no arguments
|
|
175
|
+
* to retrieve it.
|
|
176
|
+
*
|
|
177
|
+
* @returns {Record<string, ISigner>} A map of signer names to signers. Empty if no signers have been registered.
|
|
178
|
+
*/
|
|
179
|
+
getSigners () {
|
|
180
|
+
return { ...this._signers }
|
|
181
|
+
}
|
|
182
|
+
|
|
100
183
|
/**
|
|
101
184
|
* Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
|
|
102
185
|
*
|
|
103
|
-
* @
|
|
186
|
+
* @overload
|
|
104
187
|
* @param {number} [index] - The index of the account to get (default: 0).
|
|
188
|
+
* @param {Object} [options] - Account options.
|
|
189
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
105
190
|
* @returns {Promise<IWalletAccount>} The account.
|
|
191
|
+
* @throws {Error} If a signer name is given but no signer exists with that name.
|
|
192
|
+
* @throws {SignerError} If the signer doesn't support account derivation.
|
|
106
193
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Returns the wallet account associated with a registered signer. For
|
|
197
|
+
* non-derivable signers (e.g., private-key signers), returns the signer's
|
|
198
|
+
* single account. For derivable signers, returns the wallet account at the
|
|
199
|
+
* signer's root, with no further derivation.
|
|
200
|
+
*
|
|
201
|
+
* @overload
|
|
202
|
+
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
203
|
+
* @returns {Promise<IWalletAccount>} The account.
|
|
204
|
+
* @throws {Error} If no signer exists with the given name.
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
/** @abstract */
|
|
208
|
+
async getAccount (indexOrSignerName = 0, options = {}) {
|
|
209
|
+
throw new NotImplementedError('getAccount(indexOrSignerName, options?)')
|
|
109
210
|
}
|
|
110
211
|
|
|
111
212
|
/**
|
|
@@ -113,10 +214,14 @@ export default class WalletManager {
|
|
|
113
214
|
*
|
|
114
215
|
* @abstract
|
|
115
216
|
* @param {string} path - The derivation path (e.g. "0'/0/0").
|
|
217
|
+
* @param {Object} [options] - Account options.
|
|
218
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
116
219
|
* @returns {Promise<IWalletAccount>} The account.
|
|
220
|
+
* @throws {Error} If a signer name is given but no signer exists with that name.
|
|
221
|
+
* @throws {SignerError} If the signer doesn't support account derivation.
|
|
117
222
|
*/
|
|
118
|
-
async getAccountByPath (path) {
|
|
119
|
-
throw new NotImplementedError('getAccountByPath(path)')
|
|
223
|
+
async getAccountByPath (path, options = {}) {
|
|
224
|
+
throw new NotImplementedError('getAccountByPath(path, options?)')
|
|
120
225
|
}
|
|
121
226
|
|
|
122
227
|
/**
|
|
@@ -130,15 +235,23 @@ export default class WalletManager {
|
|
|
130
235
|
}
|
|
131
236
|
|
|
132
237
|
/**
|
|
133
|
-
* Disposes all
|
|
238
|
+
* Disposes all wallet accounts and signers, clearing secret material from memory.
|
|
134
239
|
*/
|
|
135
240
|
dispose () {
|
|
136
241
|
for (const account of Object.values(this._accounts)) {
|
|
137
|
-
if (account.keyPair
|
|
242
|
+
if (account.keyPair?.privateKey) {
|
|
138
243
|
account.dispose()
|
|
139
244
|
}
|
|
140
245
|
}
|
|
141
246
|
|
|
247
|
+
this._defaultSigner?.dispose()
|
|
248
|
+
|
|
249
|
+
for (const signer of Object.values(this._signers)) {
|
|
250
|
+
signer.dispose()
|
|
251
|
+
}
|
|
252
|
+
|
|
142
253
|
this._accounts = {}
|
|
254
|
+
this._defaultSigner = undefined
|
|
255
|
+
this._signers = {}
|
|
143
256
|
}
|
|
144
257
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ export type KeyPair = import("./src/wallet-account.js").KeyPair;
|
|
|
8
8
|
export { default } from "./src/wallet-manager.js";
|
|
9
9
|
export { default as WalletAccountReadOnly, IWalletAccountReadOnly } from "./src/wallet-account-read-only.js";
|
|
10
10
|
export { IWalletAccount } from "./src/wallet-account.js";
|
|
11
|
-
export { NotImplementedError } from "./src/errors.js";
|
|
11
|
+
export { NotImplementedError, SignerError } from "./src/errors.js";
|
|
12
|
+
export { ISigner } from "./src/signer.js";
|
package/types/src/errors.d.ts
CHANGED
|
@@ -6,3 +6,11 @@ export class NotImplementedError extends Error {
|
|
|
6
6
|
*/
|
|
7
7
|
constructor(methodName: string);
|
|
8
8
|
}
|
|
9
|
+
export class SignerError extends Error {
|
|
10
|
+
/**
|
|
11
|
+
* Create a new signer error.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} message - The error's message.
|
|
14
|
+
*/
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
@@ -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,40 @@ 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;
|
|
31
|
+
export type SwidgeStatus = import("./swidge-protocol.js").SwidgeStatus;
|
|
32
|
+
export type SwidgeFeeType = import("./swidge-protocol.js").SwidgeFeeType;
|
|
33
|
+
export type SwidgeProtocolConfig = import("./swidge-protocol.js").SwidgeProtocolConfig;
|
|
34
|
+
export type SwidgeOptions = import("./swidge-protocol.js").SwidgeOptions;
|
|
35
|
+
export type SwidgeCommonOptions = import("./swidge-protocol.js").SwidgeCommonOptions;
|
|
36
|
+
export type SwidgeExactInOptions = import("./swidge-protocol.js").SwidgeExactInOptions;
|
|
37
|
+
export type SwidgeExactOutOptions = import("./swidge-protocol.js").SwidgeExactOutOptions;
|
|
38
|
+
export type SwidgeFee = import("./swidge-protocol.js").SwidgeFee;
|
|
39
|
+
export type SwidgeTransaction = import("./swidge-protocol.js").SwidgeTransaction;
|
|
40
|
+
export type SwidgeQuote = import("./swidge-protocol.js").SwidgeQuote;
|
|
41
|
+
export type SwidgeResult = import("./swidge-protocol.js").SwidgeResult;
|
|
42
|
+
export type SwidgeStatusOptions = import("./swidge-protocol.js").SwidgeStatusOptions;
|
|
43
|
+
export type SwidgeStatusResult = import("./swidge-protocol.js").SwidgeStatusResult;
|
|
44
|
+
export type SwidgeSupportedChain = import("./swidge-protocol.js").SwidgeSupportedChain;
|
|
45
|
+
export type SwidgeSupportedToken = import("./swidge-protocol.js").SwidgeSupportedToken;
|
|
46
|
+
export type SwidgeSupportedTokensOptions = import("./swidge-protocol.js").SwidgeSupportedTokensOptions;
|
|
15
47
|
export { default as SwapProtocol, ISwapProtocol } from "./swap-protocol.js";
|
|
16
48
|
export { default as BridgeProtocol, IBridgeProtocol } from "./bridge-protocol.js";
|
|
17
49
|
export { default as LendingProtocol, ILendingProtocol } from "./lending-protocol.js";
|
|
50
|
+
export { default as FiatProtocol, IFiatProtocol } from "./fiat-protocol.js";
|
|
51
|
+
export { default as SwidgeProtocol, ISwidgeProtocol } from "./swidge-protocol.js";
|