@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
|
@@ -0,0 +1,402 @@
|
|
|
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
|
+
/** @typedef {import('./swap-protocol.js').ISwapProtocol} ISwapProtocol */
|
|
23
|
+
/** @typedef {import('./swap-protocol.js').SwapOptions} SwapOptions */
|
|
24
|
+
/** @typedef {import('./swap-protocol.js').SwapResult} SwapResult */
|
|
25
|
+
|
|
26
|
+
/** @typedef {import('./bridge-protocol.js').IBridgeProtocol} IBridgeProtocol */
|
|
27
|
+
/** @typedef {import('./bridge-protocol.js').BridgeOptions} BridgeOptions */
|
|
28
|
+
/** @typedef {import('./bridge-protocol.js').BridgeResult} BridgeResult */
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {'pending' | 'action-required' | 'completed' | 'failed'
|
|
32
|
+
* | 'refund-pending' | 'refunded' | 'cancelled' | 'expired' | 'partial'} SwidgeStatus
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {'network' | 'protocol' | 'affiliate' | 'other'} SwidgeFeeType
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {Object} SwidgeProtocolConfig
|
|
41
|
+
* @property {number | bigint} [maxNetworkFeeBps] - Maximum acceptable network fee in basis points of the input amount.
|
|
42
|
+
* @property {number | bigint} [maxProtocolFeeBps] - Maximum acceptable protocol fee in basis points of the input amount.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {SwidgeCommonOptions & (SwidgeExactInOptions | SwidgeExactOutOptions)} SwidgeOptions
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {Object} SwidgeCommonOptions
|
|
51
|
+
* @property {string} fromToken - The provider-specific identifier or address of the source token.
|
|
52
|
+
* @property {string} toToken - The provider-specific identifier or address of the destination token.
|
|
53
|
+
* @property {string | number} [toChain] - The identifier of the destination chain. If omitted, defaults to the source chain (same-chain swap).
|
|
54
|
+
* @property {string} [recipient] - The address that will receive the output tokens.
|
|
55
|
+
* @property {string} [refundAddress] - The address that will receive refunds if the tx cannot complete.
|
|
56
|
+
* @property {number} [slippage] - The maximum acceptable slippage as a decimal (e.g., 0.01 for 1%).
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @typedef {Object} SwidgeExactInOptions
|
|
61
|
+
* @property {number | bigint} fromTokenAmount - The exact amount of source tokens to spend (in base unit).
|
|
62
|
+
* @property {never} [toTokenAmount] - Not applicable for exact-in operations.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @typedef {Object} SwidgeExactOutOptions
|
|
67
|
+
* @property {never} [fromTokenAmount] - Not applicable for exact-out operations.
|
|
68
|
+
* @property {number | bigint} toTokenAmount - The exact amount of destination tokens to receive (in base unit).
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @typedef {Object} SwidgeFee
|
|
73
|
+
* @property {SwidgeFeeType} type - The category of the fee.
|
|
74
|
+
* @property {bigint} amount - The fee amount in base units.
|
|
75
|
+
* @property {string} token - The token in which the fee is denominated.
|
|
76
|
+
* @property {string | number} [chain] - The chain on which the fee is charged.
|
|
77
|
+
* @property {boolean} [included] - Whether the fee is already included in the quoted amounts.
|
|
78
|
+
* @property {string} [description] - A human-readable description of the fee.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @typedef {Object} SwidgeTransaction
|
|
83
|
+
* @property {string} hash - The transaction hash.
|
|
84
|
+
* @property {string | number} [chain] - The chain on which the transaction occurred.
|
|
85
|
+
* @property {'source' | 'destination' | 'approval' | 'refund' | 'other'} [type] - The role of the transaction within the swidge.
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Non-binding quote for a swidge operation.
|
|
90
|
+
* Providers that internally decompose the operation into multiple sequential transactions
|
|
91
|
+
* should encapsulate that decomposition behind a single quote.
|
|
92
|
+
*
|
|
93
|
+
* @typedef {Object} SwidgeQuote
|
|
94
|
+
* @property {bigint} fromTokenAmount - The amount of source tokens to spend.
|
|
95
|
+
* @property {bigint} toTokenAmount - The estimated amount of destination tokens to receive.
|
|
96
|
+
* @property {bigint} toTokenAmountMin - The minimum guaranteed amount after slippage.
|
|
97
|
+
* @property {SwidgeFee[]} fees - Itemised fee breakdown.
|
|
98
|
+
* @property {number} [estimatedDuration] - Estimated duration in seconds.
|
|
99
|
+
* @property {number} [expiry] - Unix timestamp (seconds) at which the quote expires.
|
|
100
|
+
* @property {number} [priceImpact] - Provider-reported estimated price impact as a decimal (e.g., 0.01 for 1%).
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @typedef {Object} SwidgeResult
|
|
105
|
+
* @property {string} id - The unique swidge execution identifier.
|
|
106
|
+
* @property {string} [hash] - The primary transaction hash (if available immediately).
|
|
107
|
+
* @property {SwidgeFee[]} fees - Itemised fee breakdown.
|
|
108
|
+
* @property {SwidgeTransaction[]} [transactions] - Transactions produced by the swidge execution.
|
|
109
|
+
* @property {bigint} fromTokenAmount - The actual amount of source tokens spent.
|
|
110
|
+
* @property {bigint} toTokenAmount - The actual or expected amount of destination tokens.
|
|
111
|
+
* @property {bigint} [toTokenAmountMin] - The minimum guaranteed amount after slippage.
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @typedef {Object} SwidgeStatusOptions
|
|
116
|
+
* @property {string | number} [fromChain] - The source chain identifier.
|
|
117
|
+
* @property {string | number} [toChain] - The destination chain identifier.
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @typedef {Object} SwidgeStatusResult
|
|
122
|
+
* @property {SwidgeStatus} status - The current status of the swidge.
|
|
123
|
+
* @property {SwidgeTransaction[]} [transactions] - Transactions associated with the swidge.
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @typedef {Object} SwidgeSupportedChain
|
|
128
|
+
* @property {string | number} id - The provider-specific chain identifier.
|
|
129
|
+
* @property {string} name - The human-readable chain name.
|
|
130
|
+
* @property {string} type - The chain or virtual machine type (e.g., 'evm', 'svm', 'utxo').
|
|
131
|
+
* @property {string} nativeToken - The symbol of the chain's native token.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @typedef {Object} SwidgeSupportedToken
|
|
136
|
+
* @property {string} token - The provider-specific token identifier to use in swidge operations.
|
|
137
|
+
* @property {string | number} chain - The chain on which the token is available.
|
|
138
|
+
* @property {string} symbol - The token symbol.
|
|
139
|
+
* @property {number} decimals - The number of decimal places for the token's base unit.
|
|
140
|
+
* @property {string} [address] - The token contract address, if applicable.
|
|
141
|
+
* @property {string} [name] - The token's full name.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @typedef {Object} SwidgeSupportedTokensOptions
|
|
146
|
+
* @property {string | number} [fromChain] - The optional source chain for route-scoped discovery.
|
|
147
|
+
* @property {string} [fromToken] - The optional source token for route-scoped discovery.
|
|
148
|
+
* @property {string | number} [toChain] - The optional destination chain for route-scoped discovery.
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @interface
|
|
153
|
+
* @implements {ISwapProtocol}
|
|
154
|
+
* @implements {IBridgeProtocol}
|
|
155
|
+
*/
|
|
156
|
+
export class ISwidgeProtocol {
|
|
157
|
+
/**
|
|
158
|
+
* Quotes the estimated costs and output of a cross-chain swap/bridge operation.
|
|
159
|
+
* Returns a non-binding quote; the actual execution is performed
|
|
160
|
+
* by {@link swidge}.
|
|
161
|
+
*
|
|
162
|
+
* @param {SwidgeOptions} options - The swidge options.
|
|
163
|
+
* @returns {Promise<SwidgeQuote>} The quoted swidge details.
|
|
164
|
+
*/
|
|
165
|
+
async quoteSwidge (options) {
|
|
166
|
+
throw new NotImplementedError('quoteSwidge(options)')
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Executes a swidge operation.
|
|
171
|
+
*
|
|
172
|
+
* @param {SwidgeOptions} options - The swidge options.
|
|
173
|
+
* @param {SwidgeProtocolConfig} [config] - Optional provider-specific execution configuration.
|
|
174
|
+
* @returns {Promise<SwidgeResult>} The swidge execution result.
|
|
175
|
+
*/
|
|
176
|
+
async swidge (options, config) {
|
|
177
|
+
throw new NotImplementedError('swidge(options, config)')
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Retrieves the current status of an in-flight swidge.
|
|
182
|
+
*
|
|
183
|
+
* @param {string} id - The swidge execution identifier returned by swidge.
|
|
184
|
+
* @param {SwidgeStatusOptions} [options] - Optional hints to assist provider lookups.
|
|
185
|
+
* @returns {Promise<SwidgeStatusResult>} The current swidge status.
|
|
186
|
+
* @throws {Error} If the id is invalid, or no swidge exists with the given identifier.
|
|
187
|
+
*/
|
|
188
|
+
async getSwidgeStatus (id, options) {
|
|
189
|
+
throw new NotImplementedError('getSwidgeStatus(id, options)')
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Retrieves the chains supported by the provider for swidge operations.
|
|
194
|
+
*
|
|
195
|
+
* @returns {Promise<SwidgeSupportedChain[]>} The supported chains.
|
|
196
|
+
*/
|
|
197
|
+
async getSupportedChains () {
|
|
198
|
+
throw new NotImplementedError('getSupportedChains()')
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Retrieves the tokens supported by the provider for swidge operations.
|
|
203
|
+
*
|
|
204
|
+
* @param {SwidgeSupportedTokensOptions} [options] - Optional filters for chain- or route-scoped token discovery.
|
|
205
|
+
* @returns {Promise<SwidgeSupportedToken[]>} The supported tokens.
|
|
206
|
+
*/
|
|
207
|
+
async getSupportedTokens (options) {
|
|
208
|
+
throw new NotImplementedError('getSupportedTokens(options)')
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @abstract
|
|
214
|
+
* @implements {ISwidgeProtocol}
|
|
215
|
+
* @implements {ISwapProtocol}
|
|
216
|
+
* @implements {IBridgeProtocol}
|
|
217
|
+
*/
|
|
218
|
+
export default class SwidgeProtocol {
|
|
219
|
+
/**
|
|
220
|
+
* Creates a new swidge protocol without binding it to a wallet account.
|
|
221
|
+
*
|
|
222
|
+
* @overload
|
|
223
|
+
* @param {undefined} [account] - The wallet account to use to interact with the protocol.
|
|
224
|
+
* @param {SwidgeProtocolConfig} [config] - The swidge protocol configuration.
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Creates a new read-only swidge protocol.
|
|
229
|
+
*
|
|
230
|
+
* @overload
|
|
231
|
+
* @param {IWalletAccountReadOnly} account - The wallet account to use to interact with the protocol.
|
|
232
|
+
* @param {SwidgeProtocolConfig} [config] - The swidge protocol configuration.
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Creates a new swidge protocol.
|
|
237
|
+
*
|
|
238
|
+
* @overload
|
|
239
|
+
* @param {IWalletAccount} account - The wallet account to use to interact with the protocol.
|
|
240
|
+
* @param {SwidgeProtocolConfig} [config] - The swidge protocol configuration.
|
|
241
|
+
*/
|
|
242
|
+
constructor (account, config = {}) {
|
|
243
|
+
/**
|
|
244
|
+
* The wallet account to use to interact with the protocol.
|
|
245
|
+
*
|
|
246
|
+
* @protected
|
|
247
|
+
* @type {IWalletAccountReadOnly | IWalletAccount | undefined}
|
|
248
|
+
*/
|
|
249
|
+
this._account = account
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The swidge protocol configuration.
|
|
253
|
+
*
|
|
254
|
+
* @protected
|
|
255
|
+
* @type {SwidgeProtocolConfig}
|
|
256
|
+
*/
|
|
257
|
+
this._config = config
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Swaps a pair of tokens by delegating to {@link swidge}.
|
|
262
|
+
*
|
|
263
|
+
* @param {SwapOptions} options - The swap's options.
|
|
264
|
+
* @returns {Promise<SwapResult>} The swap's result.
|
|
265
|
+
* @throws {Error} If no account, or a read-only account was given at construction.
|
|
266
|
+
*/
|
|
267
|
+
async swap (options) {
|
|
268
|
+
const result = await this.swidge({
|
|
269
|
+
fromToken: options.tokenIn,
|
|
270
|
+
toToken: options.tokenOut,
|
|
271
|
+
recipient: options.to,
|
|
272
|
+
fromTokenAmount: options.tokenInAmount,
|
|
273
|
+
toTokenAmount: options.tokenOutAmount
|
|
274
|
+
})
|
|
275
|
+
const fee = result.fees.reduce((acc, f) => acc + f.amount, 0n)
|
|
276
|
+
return { hash: result.id, fee, tokenInAmount: result.fromTokenAmount, tokenOutAmount: result.toTokenAmount }
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Quotes the costs of a swap operation by delegating to {@link quoteSwidge}.
|
|
281
|
+
*
|
|
282
|
+
* @param {SwapOptions} options - The swap's options.
|
|
283
|
+
* @returns {Promise<Omit<SwapResult, 'hash'>>} The swap's quotes.
|
|
284
|
+
* @throws {Error} If no account was given at construction.
|
|
285
|
+
*/
|
|
286
|
+
async quoteSwap (options) {
|
|
287
|
+
const result = await this.quoteSwidge({
|
|
288
|
+
fromToken: options.tokenIn,
|
|
289
|
+
toToken: options.tokenOut,
|
|
290
|
+
recipient: options.to,
|
|
291
|
+
fromTokenAmount: options.tokenInAmount,
|
|
292
|
+
toTokenAmount: options.tokenOutAmount
|
|
293
|
+
})
|
|
294
|
+
const fee = result.fees.reduce((acc, f) => acc + f.amount, 0n)
|
|
295
|
+
return { fee, tokenInAmount: result.fromTokenAmount, tokenOutAmount: result.toTokenAmount }
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Bridges a token to a different blockchain by delegating to {@link swidge}.
|
|
300
|
+
*
|
|
301
|
+
* @param {BridgeOptions} options - The bridge's options.
|
|
302
|
+
* @returns {Promise<BridgeResult>} The bridge's result.
|
|
303
|
+
* @throws {Error} If no account, or a read-only account was given at construction.
|
|
304
|
+
*/
|
|
305
|
+
async bridge (options) {
|
|
306
|
+
const { id: hash, fees } = await this.swidge({
|
|
307
|
+
fromToken: options.token,
|
|
308
|
+
toToken: options.token,
|
|
309
|
+
toChain: options.targetChain,
|
|
310
|
+
recipient: options.recipient,
|
|
311
|
+
fromTokenAmount: options.amount
|
|
312
|
+
})
|
|
313
|
+
const fee = fees.filter(f => f.type === 'network')
|
|
314
|
+
.reduce((acc, { amount }) => acc + amount, 0n)
|
|
315
|
+
const bridgeFee = fees.filter(f => f.type === 'protocol')
|
|
316
|
+
.reduce((acc, { amount }) => acc + amount, 0n)
|
|
317
|
+
return { hash, fee, bridgeFee }
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Quotes the costs of a bridge operation by delegating to {@link quoteSwidge}.
|
|
322
|
+
*
|
|
323
|
+
* @param {BridgeOptions} options - The bridge's options.
|
|
324
|
+
* @returns {Promise<Omit<BridgeResult, 'hash'>>} The bridge's quotes.
|
|
325
|
+
* @throws {Error} If no account was given at construction.
|
|
326
|
+
*/
|
|
327
|
+
async quoteBridge (options) {
|
|
328
|
+
const { fees } = await this.quoteSwidge({
|
|
329
|
+
fromToken: options.token,
|
|
330
|
+
toToken: options.token,
|
|
331
|
+
toChain: options.targetChain,
|
|
332
|
+
recipient: options.recipient,
|
|
333
|
+
fromTokenAmount: options.amount
|
|
334
|
+
})
|
|
335
|
+
const fee = fees.filter(f => f.type === 'network')
|
|
336
|
+
.reduce((acc, { amount }) => acc + amount, 0n)
|
|
337
|
+
const bridgeFee = fees.filter(f => f.type === 'protocol')
|
|
338
|
+
.reduce((acc, { amount }) => acc + amount, 0n)
|
|
339
|
+
return { fee, bridgeFee }
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Quotes the estimated costs and output of a swidge operation.
|
|
344
|
+
* Returns a non-binding quote; the actual execution is performed
|
|
345
|
+
* by {@link swidge}.
|
|
346
|
+
*
|
|
347
|
+
* @abstract
|
|
348
|
+
* @param {SwidgeOptions} options - The swidge options.
|
|
349
|
+
* @returns {Promise<SwidgeQuote>} The quoted swidge details.
|
|
350
|
+
* @throws {Error} If no account was given at construction.
|
|
351
|
+
*/
|
|
352
|
+
async quoteSwidge (options) {
|
|
353
|
+
throw new NotImplementedError('quoteSwidge(options)')
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Executes a swidge operation.
|
|
358
|
+
*
|
|
359
|
+
* @abstract
|
|
360
|
+
* @param {SwidgeOptions} options - The swidge options.
|
|
361
|
+
* @param {SwidgeProtocolConfig} [config] - Optional provider-specific execution configuration.
|
|
362
|
+
* @returns {Promise<SwidgeResult>} The swidge execution result.
|
|
363
|
+
* @throws {Error} If no account, or a read-only account was given at construction.
|
|
364
|
+
*/
|
|
365
|
+
async swidge (options, config) {
|
|
366
|
+
throw new NotImplementedError('swidge(options, config)')
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Retrieves the current status of an in-flight swidge.
|
|
371
|
+
*
|
|
372
|
+
* @abstract
|
|
373
|
+
* @param {string} id - The swidge execution identifier returned by swidge.
|
|
374
|
+
* @param {SwidgeStatusOptions} [options] - Optional hints to assist provider lookups.
|
|
375
|
+
* @returns {Promise<SwidgeStatusResult>} The current swidge status.
|
|
376
|
+
* @throws {Error} If the id is invalid, or no swidge exists with the given identifier.
|
|
377
|
+
*/
|
|
378
|
+
async getSwidgeStatus (id, options) {
|
|
379
|
+
throw new NotImplementedError('getSwidgeStatus(id, options)')
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Retrieves the chains supported by the provider for swidge operations.
|
|
384
|
+
*
|
|
385
|
+
* @abstract
|
|
386
|
+
* @returns {Promise<SwidgeSupportedChain[]>} The supported chains.
|
|
387
|
+
*/
|
|
388
|
+
async getSupportedChains () {
|
|
389
|
+
throw new NotImplementedError('getSupportedChains()')
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Retrieves the tokens supported by the provider for swidge operations.
|
|
394
|
+
*
|
|
395
|
+
* @abstract
|
|
396
|
+
* @param {SwidgeSupportedTokensOptions} [options] - Optional filters for chain- or route-scoped token discovery.
|
|
397
|
+
* @returns {Promise<SwidgeSupportedToken[]>} The supported tokens.
|
|
398
|
+
*/
|
|
399
|
+
async getSupportedTokens (options) {
|
|
400
|
+
throw new NotImplementedError('getSupportedTokens(options)')
|
|
401
|
+
}
|
|
402
|
+
}
|
package/src/signer.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
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').Transaction} Transaction */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A minimal, cross-chain signer interface.
|
|
22
|
+
*
|
|
23
|
+
* @interface
|
|
24
|
+
*/
|
|
25
|
+
export class ISigner {
|
|
26
|
+
/**
|
|
27
|
+
* Derive a child signer using a relative path (e.g., "0'/0/0").
|
|
28
|
+
*
|
|
29
|
+
* @param {string} relPath - The relative derivation path.
|
|
30
|
+
* @returns {Promise<ISigner>} The derived signer.
|
|
31
|
+
* @throws {SignerError} If the signer does not support derivation.
|
|
32
|
+
*/
|
|
33
|
+
async derive (relPath) {
|
|
34
|
+
throw new NotImplementedError('derive(relPath)')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Signs a transaction.
|
|
39
|
+
*
|
|
40
|
+
* @param {Transaction} tx - The transaction to sign.
|
|
41
|
+
* @returns {Promise<unknown>} The signed transaction.
|
|
42
|
+
*/
|
|
43
|
+
async signTransaction (tx) {
|
|
44
|
+
throw new NotImplementedError('signTransaction(tx)')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns the signer's address.
|
|
49
|
+
*
|
|
50
|
+
* @returns {Promise<string>} The address.
|
|
51
|
+
*/
|
|
52
|
+
async getAddress () {
|
|
53
|
+
throw new NotImplementedError('getAddress()')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Disposes the signer and clears any secret material from memory.
|
|
58
|
+
*/
|
|
59
|
+
dispose () {
|
|
60
|
+
throw new NotImplementedError('dispose()')
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -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
|
*
|
package/src/wallet-account.js
CHANGED
|
@@ -68,6 +68,16 @@ export class IWalletAccount extends IWalletAccountReadOnly {
|
|
|
68
68
|
throw new NotImplementedError('sign(message)')
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Signs a transaction
|
|
73
|
+
*
|
|
74
|
+
* @param {Transaction} tx - The transaction to sign.
|
|
75
|
+
* @returns {Promise<unknown>} The signed transaction.
|
|
76
|
+
*/
|
|
77
|
+
async signTransaction (tx) {
|
|
78
|
+
throw new NotImplementedError('signTransaction(tx)')
|
|
79
|
+
}
|
|
80
|
+
|
|
71
81
|
/**
|
|
72
82
|
* Verifies a message's signature.
|
|
73
83
|
*
|