@dynamic-labs-sdk/tempo 0.0.0-stage → 1.40.0
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/README.md +96 -2
- package/dist/TempoNetworkProvider.types.d.ts +12 -0
- package/dist/TempoNetworkProvider.types.d.ts.map +1 -0
- package/dist/TempoWalletAccount.types.d.ts +12 -0
- package/dist/TempoWalletAccount.types.d.ts.map +1 -0
- package/dist/TempoWalletProvider.types.d.ts +48 -0
- package/dist/TempoWalletProvider.types.d.ts.map +1 -0
- package/dist/addTempoExtension/addTempoExtension.d.ts +24 -0
- package/dist/addTempoExtension/addTempoExtension.d.ts.map +1 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/errors/InvalidTempoNetworkError/InvalidTempoNetworkError.d.ts +19 -0
- package/dist/errors/InvalidTempoNetworkError/InvalidTempoNetworkError.d.ts.map +1 -0
- package/dist/errors/InvalidTempoNetworkError/index.d.ts +2 -0
- package/dist/errors/InvalidTempoNetworkError/index.d.ts.map +1 -0
- package/dist/errors/TempoBusinessAccountTransactionNotSupportedError/TempoBusinessAccountTransactionNotSupportedError.d.ts +17 -0
- package/dist/errors/TempoBusinessAccountTransactionNotSupportedError/TempoBusinessAccountTransactionNotSupportedError.d.ts.map +1 -0
- package/dist/errors/TempoBusinessAccountTransactionNotSupportedError/index.d.ts +2 -0
- package/dist/errors/TempoBusinessAccountTransactionNotSupportedError/index.d.ts.map +1 -0
- package/dist/errors/TempoNativeTokenError/TempoNativeTokenError.d.ts +17 -0
- package/dist/errors/TempoNativeTokenError/TempoNativeTokenError.d.ts.map +1 -0
- package/dist/errors/TempoRawMessageNotUtf8Error/TempoRawMessageNotUtf8Error.d.ts +17 -0
- package/dist/errors/TempoRawMessageNotUtf8Error/TempoRawMessageNotUtf8Error.d.ts.map +1 -0
- package/dist/errors/TempoRawMessageNotUtf8Error/index.d.ts +2 -0
- package/dist/errors/TempoRawMessageNotUtf8Error/index.d.ts.map +1 -0
- package/dist/errors/TempoTransactionValidationError/TempoTransactionValidationError.d.ts +19 -0
- package/dist/errors/TempoTransactionValidationError/TempoTransactionValidationError.d.ts.map +1 -0
- package/dist/errors/TempoTransactionValidationError/index.d.ts +2 -0
- package/dist/errors/TempoTransactionValidationError/index.d.ts.map +1 -0
- package/dist/errors/TempoTypedDataNotSupportedError/TempoTypedDataNotSupportedError.d.ts +17 -0
- package/dist/errors/TempoTypedDataNotSupportedError/TempoTypedDataNotSupportedError.d.ts.map +1 -0
- package/dist/errors/TempoTypedDataNotSupportedError/index.d.ts +2 -0
- package/dist/errors/TempoTypedDataNotSupportedError/index.d.ts.map +1 -0
- package/dist/exports/index.d.ts +12 -0
- package/dist/exports/index.d.ts.map +1 -0
- package/dist/exports/waas.d.ts +9 -0
- package/dist/exports/waas.d.ts.map +1 -0
- package/dist/getTempoPublicClient/getTempoPublicClient.d.ts +28 -0
- package/dist/getTempoPublicClient/getTempoPublicClient.d.ts.map +1 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.esm.js +57 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/isTempoNetworkProvider/isTempoNetworkProvider.d.ts +17 -0
- package/dist/isTempoNetworkProvider/isTempoNetworkProvider.d.ts.map +1 -0
- package/dist/isTempoWalletAccount/isTempoWalletAccount.d.ts +19 -0
- package/dist/isTempoWalletAccount/isTempoWalletAccount.d.ts.map +1 -0
- package/dist/isTempoWalletProvider/isTempoWalletProvider.d.ts +21 -0
- package/dist/isTempoWalletProvider/isTempoWalletProvider.d.ts.map +1 -0
- package/dist/registerTempoNetworkProviderBuilder/registerTempoNetworkProviderBuilder.d.ts +4 -0
- package/dist/registerTempoNetworkProviderBuilder/registerTempoNetworkProviderBuilder.d.ts.map +1 -0
- package/dist/sendTip20Transaction/sendTip20Transaction.d.ts +40 -0
- package/dist/sendTip20Transaction/sendTip20Transaction.d.ts.map +1 -0
- package/dist/tempoChainIds-BVinmTlR.esm.js +236 -0
- package/dist/tempoChainIds-BVinmTlR.esm.js.map +1 -0
- package/dist/tempoChainIds-wtNAU12H.cjs +301 -0
- package/dist/tempoChainIds-wtNAU12H.cjs.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/dist/utils/createTempoNetworkProvider/createTempoNetworkProvider.d.ts +5 -0
- package/dist/utils/createTempoNetworkProvider/createTempoNetworkProvider.d.ts.map +1 -0
- package/dist/utils/mapNetworkDataToViemChain/index.d.ts +2 -0
- package/dist/utils/mapNetworkDataToViemChain/index.d.ts.map +1 -0
- package/dist/utils/mapNetworkDataToViemChain/mapNetworkDataToViemChain.d.ts +19 -0
- package/dist/utils/mapNetworkDataToViemChain/mapNetworkDataToViemChain.d.ts.map +1 -0
- package/dist/utils/tempoChainIds/tempoChainIds.d.ts +22 -0
- package/dist/utils/tempoChainIds/tempoChainIds.d.ts.map +1 -0
- package/dist/utils/tempoConfirmTransaction/index.d.ts +2 -0
- package/dist/utils/tempoConfirmTransaction/index.d.ts.map +1 -0
- package/dist/utils/tempoConfirmTransaction/tempoConfirmTransaction.d.ts +21 -0
- package/dist/utils/tempoConfirmTransaction/tempoConfirmTransaction.d.ts.map +1 -0
- package/dist/utils/tempoTransferAmount/index.d.ts +2 -0
- package/dist/utils/tempoTransferAmount/index.d.ts.map +1 -0
- package/dist/utils/tempoTransferAmount/tempoTransferAmount.d.ts +37 -0
- package/dist/utils/tempoTransferAmount/tempoTransferAmount.d.ts.map +1 -0
- package/dist/waas/WaasTempoWalletProvider.types.d.ts +23 -0
- package/dist/waas/WaasTempoWalletProvider.types.d.ts.map +1 -0
- package/dist/waas/addWaasTempoExtension/addWaasTempoExtension.d.ts +21 -0
- package/dist/waas/addWaasTempoExtension/addWaasTempoExtension.d.ts.map +1 -0
- package/dist/waas/addWaasTempoExtension/index.d.ts +2 -0
- package/dist/waas/addWaasTempoExtension/index.d.ts.map +1 -0
- package/dist/waas/sendTempoTransaction/index.d.ts +2 -0
- package/dist/waas/sendTempoTransaction/index.d.ts.map +1 -0
- package/dist/waas/sendTempoTransaction/sendTempoTransaction.d.ts +42 -0
- package/dist/waas/sendTempoTransaction/sendTempoTransaction.d.ts.map +1 -0
- package/dist/waas/utils/assertValidTempoTransactionCalls/assertValidTempoTransactionCalls.d.ts +18 -0
- package/dist/waas/utils/assertValidTempoTransactionCalls/assertValidTempoTransactionCalls.d.ts.map +1 -0
- package/dist/waas/utils/assertValidTempoTransactionCalls/index.d.ts +2 -0
- package/dist/waas/utils/assertValidTempoTransactionCalls/index.d.ts.map +1 -0
- package/dist/waas/utils/assertValidTempoTransactionRequest/assertValidTempoTransactionRequest.d.ts +41 -0
- package/dist/waas/utils/assertValidTempoTransactionRequest/assertValidTempoTransactionRequest.d.ts.map +1 -0
- package/dist/waas/utils/assertValidTempoTransactionRequest/index.d.ts +3 -0
- package/dist/waas/utils/assertValidTempoTransactionRequest/index.d.ts.map +1 -0
- package/dist/waas/utils/createViemWalletClientForWaasTempo/createViemWalletClientForWaasTempo.d.ts +41 -0
- package/dist/waas/utils/createViemWalletClientForWaasTempo/createViemWalletClientForWaasTempo.d.ts.map +1 -0
- package/dist/waas/utils/createViemWalletClientForWaasTempo/index.d.ts +2 -0
- package/dist/waas/utils/createViemWalletClientForWaasTempo/index.d.ts.map +1 -0
- package/dist/waas/utils/createWalletProviderForWaasTempo/createWalletProviderForWaasTempo.d.ts +23 -0
- package/dist/waas/utils/createWalletProviderForWaasTempo/createWalletProviderForWaasTempo.d.ts.map +1 -0
- package/dist/waas/utils/createWalletProviderForWaasTempo/index.d.ts +2 -0
- package/dist/waas/utils/createWalletProviderForWaasTempo/index.d.ts.map +1 -0
- package/dist/waas/utils/isBusinessAccountWalletAccount/index.d.ts +2 -0
- package/dist/waas/utils/isBusinessAccountWalletAccount/index.d.ts.map +1 -0
- package/dist/waas/utils/isBusinessAccountWalletAccount/isBusinessAccountWalletAccount.d.ts +23 -0
- package/dist/waas/utils/isBusinessAccountWalletAccount/isBusinessAccountWalletAccount.d.ts.map +1 -0
- package/dist/waas/utils/serializeTempoTransactionForWaas/index.d.ts +3 -0
- package/dist/waas/utils/serializeTempoTransactionForWaas/index.d.ts.map +1 -0
- package/dist/waas/utils/serializeTempoTransactionForWaas/serializeTempoTransactionForWaas.d.ts +57 -0
- package/dist/waas/utils/serializeTempoTransactionForWaas/serializeTempoTransactionForWaas.d.ts.map +1 -0
- package/dist/waas/utils/signMessage/index.d.ts +2 -0
- package/dist/waas/utils/signMessage/index.d.ts.map +1 -0
- package/dist/waas/utils/signMessage/signMessage.d.ts +38 -0
- package/dist/waas/utils/signMessage/signMessage.d.ts.map +1 -0
- package/dist/waas/utils/signRawMessage/index.d.ts +2 -0
- package/dist/waas/utils/signRawMessage/index.d.ts.map +1 -0
- package/dist/waas/utils/signRawMessage/signRawMessage.d.ts +37 -0
- package/dist/waas/utils/signRawMessage/signRawMessage.d.ts.map +1 -0
- package/dist/waas.cjs +758 -0
- package/dist/waas.cjs.map +1 -0
- package/dist/waas.esm.js +754 -0
- package/dist/waas.esm.js.map +1 -0
- package/package.json +43 -3
package/dist/waas.cjs
ADDED
|
@@ -0,0 +1,758 @@
|
|
|
1
|
+
const require_tempoChainIds = require('./tempoChainIds-wtNAU12H.cjs');
|
|
2
|
+
let _dynamic_labs_sdk_assert_package_version = require("@dynamic-labs-sdk/assert-package-version");
|
|
3
|
+
let _dynamic_labs_sdk_client = require("@dynamic-labs-sdk/client");
|
|
4
|
+
let _dynamic_labs_sdk_client_core = require("@dynamic-labs-sdk/client/core");
|
|
5
|
+
let viem = require("viem");
|
|
6
|
+
let _dynamic_labs_sdk_client_waas_core = require("@dynamic-labs-sdk/client/waas/core");
|
|
7
|
+
let _dynamic_labs_sdk_api_core = require("@dynamic-labs/sdk-api-core");
|
|
8
|
+
let viem_accounts = require("viem/accounts");
|
|
9
|
+
|
|
10
|
+
//#region src/waas/sendTempoTransaction/sendTempoTransaction.ts
|
|
11
|
+
/**
|
|
12
|
+
* Sends a Tempo transaction from a Tempo embedded wallet, including the
|
|
13
|
+
* Tempo-only fields: batched calls, a fee token, a nonce key and a validity
|
|
14
|
+
* window. Use it when a plain viem `sendTransaction` cannot express the
|
|
15
|
+
* transaction.
|
|
16
|
+
*
|
|
17
|
+
* @param params.walletAccount - The Tempo embedded wallet account that sends.
|
|
18
|
+
* @param params.calls - The calls the transaction executes atomically.
|
|
19
|
+
* @param [params.feeToken] - TIP-20 token address used to pay the fee.
|
|
20
|
+
* @param [params.gas] - Gas limit. Defaults to a buffered estimate.
|
|
21
|
+
* @param [params.nonceKey] - Nonce key selecting a parallel nonce lane.
|
|
22
|
+
* @param [params.validAfter] - Unix timestamp after which the transaction is valid.
|
|
23
|
+
* @param [params.validBefore] - Unix timestamp after which the transaction expires.
|
|
24
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple clients.
|
|
25
|
+
* @returns The transaction hash.
|
|
26
|
+
* @throws {InvalidParamError} If the wallet account is not a Tempo wallet account.
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const { transactionHash } = await sendTempoTransaction({
|
|
30
|
+
* calls: [
|
|
31
|
+
* { data: transferData, to: tokenAddress },
|
|
32
|
+
* { data: approveData, to: tokenAddress },
|
|
33
|
+
* ],
|
|
34
|
+
* feeToken: tokenAddress,
|
|
35
|
+
* walletAccount,
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
* @see sendTip20Transaction
|
|
39
|
+
* @see getTempoPublicClient
|
|
40
|
+
* @notInstrumented
|
|
41
|
+
*/
|
|
42
|
+
const sendTempoTransaction = async ({ walletAccount, ...transaction }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
|
|
43
|
+
const walletProvider = (0, _dynamic_labs_sdk_client_core.getWalletProviderFromWalletAccount)({ walletAccount }, client);
|
|
44
|
+
if (!require_tempoChainIds.isTempoWalletProvider(walletProvider)) throw new _dynamic_labs_sdk_client.InvalidParamError("Wallet account is not a Tempo wallet account");
|
|
45
|
+
(0, _dynamic_labs_sdk_client_core.assertDefined)(walletProvider.createViemWalletClient, "Tempo wallet provider cannot create a wallet client");
|
|
46
|
+
const walletClient = await walletProvider.createViemWalletClient({ walletAccount });
|
|
47
|
+
(0, _dynamic_labs_sdk_client_core.assertDefined)(walletClient.account.signTransaction, "Tempo account cannot sign transactions");
|
|
48
|
+
const serializedTransaction = await walletClient.account.signTransaction(transaction);
|
|
49
|
+
return { transactionHash: await walletClient.sendRawTransaction({ serializedTransaction }) };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/constants.ts
|
|
54
|
+
/**
|
|
55
|
+
* Chain identifier shared by every Tempo wallet provider, network provider and
|
|
56
|
+
* signing request.
|
|
57
|
+
*/
|
|
58
|
+
const TEMPO_CHAIN = "TEMPO";
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/errors/InvalidTempoNetworkError/InvalidTempoNetworkError.ts
|
|
62
|
+
/**
|
|
63
|
+
* Thrown when a Tempo wallet provider is asked to activate a network that is
|
|
64
|
+
* not a Tempo network.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* throw new InvalidTempoNetworkError({ networkId: '1' });
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @see isTempoChainId
|
|
72
|
+
* @see addWaasTempoExtension
|
|
73
|
+
*/
|
|
74
|
+
var InvalidTempoNetworkError = class extends _dynamic_labs_sdk_client.BaseError {
|
|
75
|
+
constructor({ networkId }) {
|
|
76
|
+
super({
|
|
77
|
+
cause: null,
|
|
78
|
+
code: "invalid_tempo_network_error",
|
|
79
|
+
docsUrl: null,
|
|
80
|
+
name: "InvalidTempoNetworkError",
|
|
81
|
+
shortMessage: `Network ${networkId} is not a Tempo network`
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/errors/TempoBusinessAccountTransactionNotSupportedError/TempoBusinessAccountTransactionNotSupportedError.ts
|
|
88
|
+
/**
|
|
89
|
+
* Thrown when a business-account Tempo wallet is asked to sign a transaction.
|
|
90
|
+
* Business-account transactions need a signing-quorum intent, which the
|
|
91
|
+
* embedded wallet signer does not support for Tempo transactions yet.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* throw new TempoBusinessAccountTransactionNotSupportedError();
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @see addWaasTempoExtension
|
|
99
|
+
*/
|
|
100
|
+
var TempoBusinessAccountTransactionNotSupportedError = class extends _dynamic_labs_sdk_client.BaseError {
|
|
101
|
+
constructor() {
|
|
102
|
+
super({
|
|
103
|
+
cause: null,
|
|
104
|
+
code: "tempo_business_account_transaction_not_supported_error",
|
|
105
|
+
docsUrl: null,
|
|
106
|
+
name: "TempoBusinessAccountTransactionNotSupportedError",
|
|
107
|
+
shortMessage: "Signing Tempo transactions with a business account wallet is not supported"
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/utils/tempoConfirmTransaction/tempoConfirmTransaction.ts
|
|
114
|
+
/**
|
|
115
|
+
* Waits until a transaction sent from a Tempo wallet account is included in a
|
|
116
|
+
* block.
|
|
117
|
+
*
|
|
118
|
+
* @param params.transactionHash - The hash of the transaction to wait for.
|
|
119
|
+
* @param params.walletAccount - The Tempo wallet account that sent it.
|
|
120
|
+
* @param client - The Dynamic client instance.
|
|
121
|
+
* @returns Nothing. Resolves once the transaction receipt is available.
|
|
122
|
+
* @throws {InvalidParamError} If the wallet account is not a Tempo wallet account.
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* await tempoConfirmTransaction({ transactionHash, walletAccount }, client);
|
|
126
|
+
* ```
|
|
127
|
+
* @see tempoTransferAmount
|
|
128
|
+
* @see getTempoPublicClient
|
|
129
|
+
* @notInstrumented
|
|
130
|
+
*/
|
|
131
|
+
const tempoConfirmTransaction = async ({ transactionHash, walletAccount }, client) => {
|
|
132
|
+
if (!require_tempoChainIds.isTempoWalletAccount(walletAccount)) throw new _dynamic_labs_sdk_client.InvalidParamError("Wallet account is not a Tempo wallet account");
|
|
133
|
+
await (await require_tempoChainIds.getTempoPublicClient({ walletAccount }, client)).waitForTransactionReceipt({ hash: transactionHash });
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/utils/tempoTransferAmount/tempoTransferAmount.ts
|
|
138
|
+
/**
|
|
139
|
+
* Transfers a TIP-20 token from a Tempo wallet account. Tempo has no native
|
|
140
|
+
* token, so the token is required.
|
|
141
|
+
*
|
|
142
|
+
* @param params.amount - Human-readable amount, e.g. '1.5'.
|
|
143
|
+
* @param params.recipient - Recipient address.
|
|
144
|
+
* @param params.token - The TIP-20 token to transfer.
|
|
145
|
+
* @param params.walletAccount - The Tempo wallet account that sends.
|
|
146
|
+
* @param params.createViemWalletClient - Creates the viem wallet client that signs.
|
|
147
|
+
* @returns The transaction hash.
|
|
148
|
+
* @throws {InvalidParamError} If the wallet account is not a Tempo wallet account.
|
|
149
|
+
* @throws {TempoNativeTokenError} If no token is provided.
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const { transactionHash } = await tempoTransferAmount({
|
|
153
|
+
* amount: '1.5',
|
|
154
|
+
* createViemWalletClient,
|
|
155
|
+
* recipient: '0xRecipient',
|
|
156
|
+
* token: { address: '0xTip20Token', decimals: 6 },
|
|
157
|
+
* walletAccount,
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
160
|
+
* @see sendTip20Transaction
|
|
161
|
+
* @see tempoConfirmTransaction
|
|
162
|
+
* @notInstrumented
|
|
163
|
+
*/
|
|
164
|
+
const tempoTransferAmount = async ({ amount, createViemWalletClient, recipient, token, walletAccount }) => {
|
|
165
|
+
if (!require_tempoChainIds.isTempoWalletAccount(walletAccount)) throw new _dynamic_labs_sdk_client.InvalidParamError("Wallet account is not a Tempo wallet account");
|
|
166
|
+
if (!token?.address) throw new require_tempoChainIds.TempoNativeTokenError();
|
|
167
|
+
const walletClient = await createViemWalletClient({ walletAccount });
|
|
168
|
+
return { transactionHash: await require_tempoChainIds.sendTip20Transaction({
|
|
169
|
+
amount,
|
|
170
|
+
decimals: token.decimals,
|
|
171
|
+
to: recipient,
|
|
172
|
+
tokenAddress: token.address,
|
|
173
|
+
walletClient
|
|
174
|
+
}) };
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/errors/TempoRawMessageNotUtf8Error/TempoRawMessageNotUtf8Error.ts
|
|
179
|
+
/**
|
|
180
|
+
* Thrown when a raw message passed to a Tempo embedded wallet is not valid
|
|
181
|
+
* UTF-8 text. The embedded wallet signs text messages, so bytes that cannot be
|
|
182
|
+
* decoded and re-encoded unchanged would be signed as different bytes.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* throw new TempoRawMessageNotUtf8Error();
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @see createWalletProviderForWaasTempo
|
|
190
|
+
*/
|
|
191
|
+
var TempoRawMessageNotUtf8Error = class extends _dynamic_labs_sdk_client.BaseError {
|
|
192
|
+
constructor() {
|
|
193
|
+
super({
|
|
194
|
+
cause: null,
|
|
195
|
+
code: "tempo_raw_message_not_utf8_error",
|
|
196
|
+
docsUrl: null,
|
|
197
|
+
name: "TempoRawMessageNotUtf8Error",
|
|
198
|
+
shortMessage: "Raw messages must be valid UTF-8 text to be signed by a Tempo embedded wallet"
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/errors/TempoTransactionValidationError/TempoTransactionValidationError.ts
|
|
205
|
+
/**
|
|
206
|
+
* Thrown when a Tempo transaction fails validation before signing, for
|
|
207
|
+
* example because of a malformed address or non-hex call data.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* throw new TempoTransactionValidationError({ reason: 'malformed call data' });
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @see createWalletProviderForWaasTempo
|
|
215
|
+
* @see addWaasTempoExtension
|
|
216
|
+
*/
|
|
217
|
+
var TempoTransactionValidationError = class extends _dynamic_labs_sdk_client.BaseError {
|
|
218
|
+
constructor({ reason }) {
|
|
219
|
+
super({
|
|
220
|
+
cause: null,
|
|
221
|
+
code: "tempo_transaction_validation_error",
|
|
222
|
+
docsUrl: null,
|
|
223
|
+
name: "TempoTransactionValidationError",
|
|
224
|
+
shortMessage: `Invalid Tempo transaction: ${reason}`
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/errors/TempoTypedDataNotSupportedError/TempoTypedDataNotSupportedError.ts
|
|
231
|
+
/**
|
|
232
|
+
* Thrown when typed data is signed with a Tempo embedded wallet, which does
|
|
233
|
+
* not support it yet.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* throw new TempoTypedDataNotSupportedError();
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* @see createWalletProviderForWaasTempo
|
|
241
|
+
* @see addWaasTempoExtension
|
|
242
|
+
*/
|
|
243
|
+
var TempoTypedDataNotSupportedError = class extends _dynamic_labs_sdk_client.BaseError {
|
|
244
|
+
constructor() {
|
|
245
|
+
super({
|
|
246
|
+
cause: null,
|
|
247
|
+
code: "tempo_typed_data_not_supported",
|
|
248
|
+
docsUrl: null,
|
|
249
|
+
name: "TempoTypedDataNotSupportedError",
|
|
250
|
+
shortMessage: "Signing typed data is not supported for Tempo embedded wallets yet"
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/waas/utils/assertValidTempoTransactionCalls/assertValidTempoTransactionCalls.ts
|
|
257
|
+
/**
|
|
258
|
+
* Rejects malformed calls before they reach the signer, which would otherwise
|
|
259
|
+
* fail with an opaque parsing error.
|
|
260
|
+
*
|
|
261
|
+
* @param params.calls - The Tempo calls to validate.
|
|
262
|
+
* @returns Nothing. Throws on malformed input.
|
|
263
|
+
* @throws {TempoTransactionValidationError} If a call is malformed or the batch is empty.
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* assertValidTempoTransactionCalls({ calls: [{ to, data, value }] });
|
|
267
|
+
* ```
|
|
268
|
+
* @notInstrumented
|
|
269
|
+
*/
|
|
270
|
+
const assertValidTempoTransactionCalls = ({ calls }) => {
|
|
271
|
+
if (calls.length === 0) throw new TempoTransactionValidationError({ reason: "at least one call is required" });
|
|
272
|
+
for (const call of calls) {
|
|
273
|
+
if (call.to !== void 0 && !(0, viem.isAddress)(call.to)) throw new TempoTransactionValidationError({ reason: "malformed call address" });
|
|
274
|
+
if (call.data !== void 0 && !(0, viem.isHex)(call.data)) throw new TempoTransactionValidationError({ reason: "malformed call data" });
|
|
275
|
+
if (call.value !== void 0 && typeof call.value !== "bigint") throw new TempoTransactionValidationError({ reason: "malformed call value" });
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/waas/utils/assertValidTempoTransactionRequest/assertValidTempoTransactionRequest.ts
|
|
281
|
+
/**
|
|
282
|
+
* Rejects malformed Tempo transaction fields before they reach the signer,
|
|
283
|
+
* which would otherwise fail with an opaque parsing error.
|
|
284
|
+
*
|
|
285
|
+
* @param params.transaction - The Tempo transaction request to validate.
|
|
286
|
+
* @param params.chainId - The chain id of the active Tempo network.
|
|
287
|
+
* @returns Nothing. Throws on malformed input.
|
|
288
|
+
* @throws {TempoTransactionValidationError} If a field is malformed or inconsistent.
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* assertValidTempoTransactionRequest({ transaction, chainId: 4217 });
|
|
292
|
+
* ```
|
|
293
|
+
* @notInstrumented
|
|
294
|
+
*/
|
|
295
|
+
const assertValidTempoTransactionRequest = ({ transaction, chainId }) => {
|
|
296
|
+
if (transaction.feeToken !== void 0 && !(0, viem.isAddress)(transaction.feeToken)) throw new TempoTransactionValidationError({ reason: "malformed feeToken address" });
|
|
297
|
+
if (transaction.calls !== void 0 && (transaction.to !== void 0 || transaction.data !== void 0 || transaction.value !== void 0)) throw new TempoTransactionValidationError({ reason: "calls cannot be combined with top-level to, data or value" });
|
|
298
|
+
if (transaction.chainId !== void 0 && transaction.chainId !== chainId) throw new TempoTransactionValidationError({ reason: "chainId does not match the active Tempo network" });
|
|
299
|
+
if (transaction.nonceKey !== void 0 && (typeof transaction.nonceKey !== "bigint" || transaction.nonceKey < 0n)) throw new TempoTransactionValidationError({ reason: "nonceKey must be a non-negative bigint" });
|
|
300
|
+
for (const field of ["validAfter", "validBefore"]) {
|
|
301
|
+
const value = transaction[field];
|
|
302
|
+
if (value !== void 0 && (!Number.isInteger(value) || value < 0)) throw new TempoTransactionValidationError({ reason: `${field} must be a non-negative integer timestamp` });
|
|
303
|
+
}
|
|
304
|
+
if (transaction.validAfter !== void 0 && transaction.validBefore !== void 0 && transaction.validAfter >= transaction.validBefore) throw new TempoTransactionValidationError({ reason: "validAfter must be before validBefore" });
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/waas/utils/isBusinessAccountWalletAccount/isBusinessAccountWalletAccount.ts
|
|
309
|
+
/**
|
|
310
|
+
* Type guard — returns true if the wallet account belongs to a business
|
|
311
|
+
* account, meaning its signatures need a signing-quorum approval.
|
|
312
|
+
*
|
|
313
|
+
* @param walletAccount - The wallet account to check.
|
|
314
|
+
* @returns Whether the wallet account has a business account id.
|
|
315
|
+
* @example
|
|
316
|
+
* ```ts
|
|
317
|
+
* if (isBusinessAccountWalletAccount(walletAccount)) {
|
|
318
|
+
* console.log(walletAccount.businessAccountId);
|
|
319
|
+
* }
|
|
320
|
+
* ```
|
|
321
|
+
* @see signMessage
|
|
322
|
+
* @see signRawMessage
|
|
323
|
+
* @notInstrumented
|
|
324
|
+
*/
|
|
325
|
+
const isBusinessAccountWalletAccount = (walletAccount) => "businessAccountId" in walletAccount && typeof walletAccount.businessAccountId === "string" && walletAccount.businessAccountId !== "";
|
|
326
|
+
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/waas/utils/serializeTempoTransactionForWaas/serializeTempoTransactionForWaas.ts
|
|
329
|
+
/**
|
|
330
|
+
* Serializes a Tempo transaction to the JSON an embedded wallet signs.
|
|
331
|
+
* BigInt values are written as decimal strings because JSON has no BigInt type.
|
|
332
|
+
*
|
|
333
|
+
* @param params - The Tempo transaction fields to serialize.
|
|
334
|
+
* @returns The JSON-encoded transaction.
|
|
335
|
+
* @example
|
|
336
|
+
* ```ts
|
|
337
|
+
* const transaction = serializeTempoTransactionForWaas({
|
|
338
|
+
* calls: [{ to: '0xabc', value: 1n }],
|
|
339
|
+
* chainId: 4217,
|
|
340
|
+
* gas: 300_000n,
|
|
341
|
+
* maxFeePerGas: 1_000n,
|
|
342
|
+
* maxPriorityFeePerGas: 100n,
|
|
343
|
+
* nonce: 0,
|
|
344
|
+
* });
|
|
345
|
+
* ```
|
|
346
|
+
* @see addWaasTempoExtension
|
|
347
|
+
* @see createWalletProviderForWaasTempo
|
|
348
|
+
* @notInstrumented
|
|
349
|
+
*/
|
|
350
|
+
const serializeTempoTransactionForWaas = ({ calls, chainId, feeToken, gas, maxFeePerGas, maxPriorityFeePerGas, nonce, nonceKey, validAfter, validBefore }) => JSON.stringify({
|
|
351
|
+
calls: calls.map(({ data, to, value }) => ({
|
|
352
|
+
data,
|
|
353
|
+
to,
|
|
354
|
+
value
|
|
355
|
+
})),
|
|
356
|
+
chainId,
|
|
357
|
+
feeToken,
|
|
358
|
+
gas,
|
|
359
|
+
maxFeePerGas,
|
|
360
|
+
maxPriorityFeePerGas,
|
|
361
|
+
nonce,
|
|
362
|
+
nonceKey,
|
|
363
|
+
validAfter,
|
|
364
|
+
validBefore
|
|
365
|
+
}, (_key, value) => typeof value === "bigint" ? value.toString() : value);
|
|
366
|
+
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/waas/utils/signMessage/signMessage.ts
|
|
369
|
+
/**
|
|
370
|
+
* Signs a message with a Tempo embedded wallet account.
|
|
371
|
+
*
|
|
372
|
+
* For a business-account wallet, this first prepares and signs the quorum
|
|
373
|
+
* intent for the message. Personal wallets pass `approvalQuorum` through
|
|
374
|
+
* unchanged.
|
|
375
|
+
*
|
|
376
|
+
* @param params.approvalQuorum - A signed intent from an earlier `SigningConsentRequiredError`, when retrying.
|
|
377
|
+
* @param params.message - The message to sign.
|
|
378
|
+
* @param params.waasProvider - The WaaS provider that prepares the intent and signs.
|
|
379
|
+
* @param params.walletAccount - The wallet account that signs the message.
|
|
380
|
+
* @param client - The Dynamic client holding the current session key.
|
|
381
|
+
* @returns The signature.
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* const { signature } = await signMessage(
|
|
385
|
+
* { message, waasProvider, walletAccount },
|
|
386
|
+
* client
|
|
387
|
+
* );
|
|
388
|
+
* ```
|
|
389
|
+
* @see {@link prepareSigningQuorumApproval} for the quorum intent step.
|
|
390
|
+
* @see {@link isSigningConsentRequiredError} for handling an unmet signing quorum.
|
|
391
|
+
* @notInstrumented
|
|
392
|
+
*/
|
|
393
|
+
const signMessage = async ({ approvalQuorum, message, waasProvider, walletAccount }, client) => {
|
|
394
|
+
const preparedApprovalQuorum = await (0, _dynamic_labs_sdk_client_waas_core.prepareSigningQuorumApproval)({
|
|
395
|
+
approvalQuorum,
|
|
396
|
+
chainName: TEMPO_CHAIN,
|
|
397
|
+
operation: {
|
|
398
|
+
kind: "message",
|
|
399
|
+
message
|
|
400
|
+
},
|
|
401
|
+
waasClient: await waasProvider.getWaasClient(),
|
|
402
|
+
walletAccount
|
|
403
|
+
}, client);
|
|
404
|
+
return waasProvider.signMessage({
|
|
405
|
+
approvalQuorum: preparedApprovalQuorum,
|
|
406
|
+
message,
|
|
407
|
+
walletAccount
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/waas/utils/createViemWalletClientForWaasTempo/createViemWalletClientForWaasTempo.ts
|
|
413
|
+
const TEMPO_GAS_BUFFER_NUMERATOR = 130n;
|
|
414
|
+
const TEMPO_GAS_BUFFER_DENOMINATOR = 100n;
|
|
415
|
+
const TEMPO_MIN_GAS = 300000n;
|
|
416
|
+
/**
|
|
417
|
+
* Address of the Tempo nonce manager, which keeps one nonce counter per
|
|
418
|
+
* account and nonce key.
|
|
419
|
+
*/
|
|
420
|
+
const TEMPO_NONCE_MANAGER_ADDRESS = "0x4e4F4E4345000000000000000000000000000000";
|
|
421
|
+
const TEMPO_NONCE_MANAGER_ABI = [{
|
|
422
|
+
inputs: [{
|
|
423
|
+
name: "account",
|
|
424
|
+
type: "address"
|
|
425
|
+
}, {
|
|
426
|
+
name: "nonceKey",
|
|
427
|
+
type: "uint256"
|
|
428
|
+
}],
|
|
429
|
+
name: "getNonce",
|
|
430
|
+
outputs: [{
|
|
431
|
+
name: "nonce",
|
|
432
|
+
type: "uint64"
|
|
433
|
+
}],
|
|
434
|
+
stateMutability: "view",
|
|
435
|
+
type: "function"
|
|
436
|
+
}];
|
|
437
|
+
/**
|
|
438
|
+
* Creates a viem wallet client for a Tempo embedded wallet account.
|
|
439
|
+
*
|
|
440
|
+
* Transactions are signed as Tempo transactions: batched `calls`, `feeToken`,
|
|
441
|
+
* `nonceKey` and `validAfter` / `validBefore` pass through to the signer. Gas
|
|
442
|
+
* is the larger of the caller's value and a 30% buffered estimate with a 300k
|
|
443
|
+
* floor, fees are at least the network gas price, and the nonce is the next
|
|
444
|
+
* one on the requested nonce lane.
|
|
445
|
+
*
|
|
446
|
+
* @param params.waasProvider - The embedded wallet provider that signs.
|
|
447
|
+
* @param params.walletAccount - The Tempo embedded wallet account that signs.
|
|
448
|
+
* @param [params.httpTransportConfig] - Optional viem HTTP transport config.
|
|
449
|
+
* @param [params.viemWalletClientConfig] - Optional extra viem client config.
|
|
450
|
+
* @param client - The Dynamic client instance.
|
|
451
|
+
* @returns A viem wallet client bound to the Tempo account.
|
|
452
|
+
* @throws If no active network data exists for the wallet account.
|
|
453
|
+
* @example
|
|
454
|
+
* ```ts
|
|
455
|
+
* const walletClient = await createViemWalletClientForWaasTempo(
|
|
456
|
+
* { waasProvider, walletAccount },
|
|
457
|
+
* client
|
|
458
|
+
* );
|
|
459
|
+
*
|
|
460
|
+
* const hash = await walletClient.sendTransaction({ to, data });
|
|
461
|
+
* ```
|
|
462
|
+
* @see serializeTempoTransactionForWaas
|
|
463
|
+
* @see createWalletProviderForWaasTempo
|
|
464
|
+
* @notInstrumented
|
|
465
|
+
*/
|
|
466
|
+
const createViemWalletClientForWaasTempo = async ({ waasProvider, walletAccount, httpTransportConfig, viemWalletClientConfig }, dynamicClient) => {
|
|
467
|
+
const { networkData: activeNetworkData } = await (0, _dynamic_labs_sdk_client.getActiveNetworkData)({ walletAccount }, dynamicClient);
|
|
468
|
+
(0, _dynamic_labs_sdk_client_core.assertDefined)(activeNetworkData, "No active network data found for the provided wallet account");
|
|
469
|
+
const chain = require_tempoChainIds.mapNetworkDataToViemChain(activeNetworkData);
|
|
470
|
+
const transport = (0, viem.http)(activeNetworkData.rpcUrls.http[0], httpTransportConfig);
|
|
471
|
+
const publicClient = (0, viem.createPublicClient)({
|
|
472
|
+
chain,
|
|
473
|
+
transport
|
|
474
|
+
});
|
|
475
|
+
const estimateTempoGas = async ({ calls, hasExplicitGas }) => {
|
|
476
|
+
const buffered = (await Promise.all(calls.map(async (call) => {
|
|
477
|
+
try {
|
|
478
|
+
return await publicClient.estimateGas({
|
|
479
|
+
account: walletAccount.address,
|
|
480
|
+
data: call.data,
|
|
481
|
+
to: call.to,
|
|
482
|
+
value: call.value
|
|
483
|
+
});
|
|
484
|
+
} catch (error) {
|
|
485
|
+
if (calls.length === 1 && !hasExplicitGas) throw error;
|
|
486
|
+
return TEMPO_MIN_GAS;
|
|
487
|
+
}
|
|
488
|
+
}))).reduce((total, value) => total + value, 0n) * TEMPO_GAS_BUFFER_NUMERATOR / TEMPO_GAS_BUFFER_DENOMINATOR;
|
|
489
|
+
return buffered > TEMPO_MIN_GAS ? buffered : TEMPO_MIN_GAS;
|
|
490
|
+
};
|
|
491
|
+
const getTempoNonce = async ({ nonceKey }) => {
|
|
492
|
+
if (nonceKey === void 0 || nonceKey === 0n) return publicClient.getTransactionCount({ address: walletAccount.address });
|
|
493
|
+
return Number(await publicClient.readContract({
|
|
494
|
+
abi: TEMPO_NONCE_MANAGER_ABI,
|
|
495
|
+
address: TEMPO_NONCE_MANAGER_ADDRESS,
|
|
496
|
+
args: [walletAccount.address, nonceKey],
|
|
497
|
+
functionName: "getNonce"
|
|
498
|
+
}));
|
|
499
|
+
};
|
|
500
|
+
return (0, viem.createWalletClient)({
|
|
501
|
+
account: (0, viem_accounts.toAccount)({
|
|
502
|
+
address: walletAccount.address,
|
|
503
|
+
signMessage: async ({ message }) => {
|
|
504
|
+
let signableMessage;
|
|
505
|
+
if (typeof message === "string") signableMessage = message;
|
|
506
|
+
else {
|
|
507
|
+
const raw = (0, viem.isHex)(message.raw) ? message.raw : (0, viem.bytesToHex)(message.raw);
|
|
508
|
+
signableMessage = (0, viem.hexToString)(raw);
|
|
509
|
+
if ((0, viem.stringToHex)(signableMessage) !== raw.toLowerCase()) throw new TempoRawMessageNotUtf8Error();
|
|
510
|
+
}
|
|
511
|
+
const { signature } = await signMessage({
|
|
512
|
+
message: signableMessage,
|
|
513
|
+
waasProvider,
|
|
514
|
+
walletAccount
|
|
515
|
+
}, dynamicClient);
|
|
516
|
+
return signature;
|
|
517
|
+
},
|
|
518
|
+
signTransaction: async (transaction) => {
|
|
519
|
+
if (isBusinessAccountWalletAccount(walletAccount)) throw new TempoBusinessAccountTransactionNotSupportedError();
|
|
520
|
+
assertValidTempoTransactionRequest({
|
|
521
|
+
chainId: chain.id,
|
|
522
|
+
transaction
|
|
523
|
+
});
|
|
524
|
+
const calls = transaction.calls ?? [{
|
|
525
|
+
data: transaction.data ?? "0x",
|
|
526
|
+
to: transaction.to ?? void 0,
|
|
527
|
+
value: transaction.value ?? 0n
|
|
528
|
+
}];
|
|
529
|
+
assertValidTempoTransactionCalls({ calls });
|
|
530
|
+
const estimatedGas = await estimateTempoGas({
|
|
531
|
+
calls,
|
|
532
|
+
hasExplicitGas: transaction.gas !== void 0
|
|
533
|
+
});
|
|
534
|
+
const gas = transaction.gas !== void 0 && transaction.gas > estimatedGas ? transaction.gas : estimatedGas;
|
|
535
|
+
const nonce = transaction.nonceKey !== void 0 && transaction.nonceKey !== 0n ? await getTempoNonce({ nonceKey: transaction.nonceKey }) : transaction.nonce ?? await getTempoNonce({ nonceKey: transaction.nonceKey });
|
|
536
|
+
const gasPrice = await publicClient.getGasPrice();
|
|
537
|
+
const priorityGasPrice = gasPrice / 10n;
|
|
538
|
+
const requestedGasPrice = "gasPrice" in transaction ? transaction.gasPrice : void 0;
|
|
539
|
+
const requestedMaxFeePerGas = transaction.maxFeePerGas ?? requestedGasPrice;
|
|
540
|
+
const requestedMaxPriorityFeePerGas = transaction.maxPriorityFeePerGas ?? requestedGasPrice;
|
|
541
|
+
const maxFeePerGas = requestedMaxFeePerGas !== void 0 && requestedMaxFeePerGas > gasPrice ? requestedMaxFeePerGas : gasPrice;
|
|
542
|
+
const maxPriorityFeePerGas = requestedMaxPriorityFeePerGas !== void 0 && requestedMaxPriorityFeePerGas > priorityGasPrice ? requestedMaxPriorityFeePerGas : priorityGasPrice;
|
|
543
|
+
if (maxPriorityFeePerGas > maxFeePerGas) throw new TempoTransactionValidationError({ reason: "maxPriorityFeePerGas must not exceed maxFeePerGas" });
|
|
544
|
+
const serializedTransaction = serializeTempoTransactionForWaas({
|
|
545
|
+
calls,
|
|
546
|
+
chainId: chain.id,
|
|
547
|
+
feeToken: transaction.feeToken,
|
|
548
|
+
gas,
|
|
549
|
+
maxFeePerGas,
|
|
550
|
+
maxPriorityFeePerGas,
|
|
551
|
+
nonce,
|
|
552
|
+
nonceKey: transaction.nonceKey,
|
|
553
|
+
validAfter: transaction.validAfter,
|
|
554
|
+
validBefore: transaction.validBefore
|
|
555
|
+
});
|
|
556
|
+
const { signature } = await waasProvider.signSerializedTransaction({
|
|
557
|
+
serializedTransaction,
|
|
558
|
+
walletAccount
|
|
559
|
+
});
|
|
560
|
+
return signature;
|
|
561
|
+
},
|
|
562
|
+
signTypedData: () => {
|
|
563
|
+
throw new TempoTypedDataNotSupportedError();
|
|
564
|
+
}
|
|
565
|
+
}),
|
|
566
|
+
chain,
|
|
567
|
+
transport,
|
|
568
|
+
...viemWalletClientConfig
|
|
569
|
+
});
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region src/waas/utils/signRawMessage/signRawMessage.ts
|
|
574
|
+
/**
|
|
575
|
+
* Signs a raw message with a Tempo embedded wallet account.
|
|
576
|
+
*
|
|
577
|
+
* For a business-account wallet, `rawSign` is required: the quorum intent
|
|
578
|
+
* commits to its preimage, so the intent can be checked before signing.
|
|
579
|
+
*
|
|
580
|
+
* @param params.approvalQuorum - A signed intent from an earlier `SigningConsentRequiredError`, when retrying.
|
|
581
|
+
* @param params.message - The raw message to sign.
|
|
582
|
+
* @param [params.password] - The wallet password, if the wallet is password protected.
|
|
583
|
+
* @param [params.rawSign] - The hex preimage and hash metadata that the intent commits to.
|
|
584
|
+
* @param params.waasProvider - The WaaS provider that prepares the intent and signs.
|
|
585
|
+
* @param params.walletAccount - The wallet account that signs the message.
|
|
586
|
+
* @param client - The Dynamic client holding the current session key.
|
|
587
|
+
* @returns The signature.
|
|
588
|
+
* @throws {InvalidParamError} If a business-account wallet has no `rawSign`.
|
|
589
|
+
* @example
|
|
590
|
+
* ```ts
|
|
591
|
+
* const { signature } = await signRawMessage(
|
|
592
|
+
* { message, rawSign, waasProvider, walletAccount },
|
|
593
|
+
* client
|
|
594
|
+
* );
|
|
595
|
+
* ```
|
|
596
|
+
* @see {@link prepareSigningQuorumApproval} for the quorum intent step.
|
|
597
|
+
* @see {@link isSigningConsentRequiredError} for handling an unmet signing quorum.
|
|
598
|
+
* @notInstrumented
|
|
599
|
+
*/
|
|
600
|
+
const signRawMessage = async ({ approvalQuorum, message, password, rawSign, waasProvider, walletAccount }, client) => {
|
|
601
|
+
if (isBusinessAccountWalletAccount(walletAccount) && !rawSign) throw new _dynamic_labs_sdk_client.InvalidParamError("Raw signing for a business-account wallet requires a verifiable preimage");
|
|
602
|
+
const preparedApprovalQuorum = rawSign ? await (0, _dynamic_labs_sdk_client_waas_core.prepareSigningQuorumApproval)({
|
|
603
|
+
approvalQuorum,
|
|
604
|
+
chainName: TEMPO_CHAIN,
|
|
605
|
+
operation: {
|
|
606
|
+
kind: "raw",
|
|
607
|
+
message,
|
|
608
|
+
rawSign
|
|
609
|
+
},
|
|
610
|
+
waasClient: await waasProvider.getWaasClient(),
|
|
611
|
+
walletAccount
|
|
612
|
+
}, client) : approvalQuorum;
|
|
613
|
+
return waasProvider.signRawMessage({
|
|
614
|
+
approvalQuorum: preparedApprovalQuorum,
|
|
615
|
+
message,
|
|
616
|
+
password,
|
|
617
|
+
rawSign,
|
|
618
|
+
walletAccount
|
|
619
|
+
});
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
//#endregion
|
|
623
|
+
//#region src/waas/utils/createWalletProviderForWaasTempo/createWalletProviderForWaasTempo.ts
|
|
624
|
+
/**
|
|
625
|
+
* Creates the embedded wallet provider for the Tempo chain.
|
|
626
|
+
*
|
|
627
|
+
* @param params.dynamicClient - The Dynamic client the provider is bound to.
|
|
628
|
+
* @returns A wallet provider that signs with Tempo embedded wallets.
|
|
629
|
+
* @throws {InvalidTempoNetworkError} When the returned provider is asked to switch to a network that is not a Tempo network.
|
|
630
|
+
* @throws {TempoBusinessAccountTransactionNotSupportedError} When the returned provider is asked to sign a transaction with a business-account wallet.
|
|
631
|
+
* @example
|
|
632
|
+
* ```ts
|
|
633
|
+
* const walletProvider = createWalletProviderForWaasTempo({ dynamicClient });
|
|
634
|
+
* ```
|
|
635
|
+
* @see addWaasTempoExtension
|
|
636
|
+
* @see WaasTempoWalletProvider
|
|
637
|
+
* @notInstrumented
|
|
638
|
+
*/
|
|
639
|
+
const createWalletProviderForWaasTempo = ({ dynamicClient }) => {
|
|
640
|
+
const chain = TEMPO_CHAIN;
|
|
641
|
+
const walletProviderType = _dynamic_labs_sdk_api_core.WalletProviderEnum.EmbeddedWallet;
|
|
642
|
+
const key = (0, _dynamic_labs_sdk_client_core.formatWalletProviderKey)({
|
|
643
|
+
chain,
|
|
644
|
+
displayName: _dynamic_labs_sdk_client_waas_core.DYNAMIC_WAAS_METADATA.displayName,
|
|
645
|
+
walletProviderType
|
|
646
|
+
});
|
|
647
|
+
const waasProvider = (0, _dynamic_labs_sdk_client_waas_core.createWaasProvider)({
|
|
648
|
+
chain,
|
|
649
|
+
sdkClient: dynamicClient
|
|
650
|
+
});
|
|
651
|
+
const createViemWalletClient = async ({ walletAccount, httpTransportConfig, viemWalletClientConfig }) => createViemWalletClientForWaasTempo({
|
|
652
|
+
httpTransportConfig,
|
|
653
|
+
viemWalletClientConfig,
|
|
654
|
+
waasProvider,
|
|
655
|
+
walletAccount
|
|
656
|
+
}, dynamicClient);
|
|
657
|
+
const getActiveNetworkId = () => (0, _dynamic_labs_sdk_client_core.getActiveNetworkIdFromLastKnownRegistry)({
|
|
658
|
+
client: dynamicClient,
|
|
659
|
+
walletProviderKey: key
|
|
660
|
+
});
|
|
661
|
+
const getConnectedAddresses = () => Promise.resolve({ addresses: (0, _dynamic_labs_sdk_client_waas_core.getAllUserWaasAddressesForChain)({ chain }, dynamicClient) });
|
|
662
|
+
const signMessage$1 = async ({ approvalQuorum, message, walletAccount }) => {
|
|
663
|
+
(0, _dynamic_labs_sdk_client_core.assertDefined)(walletAccount, "Wallet account is required");
|
|
664
|
+
return signMessage({
|
|
665
|
+
approvalQuorum,
|
|
666
|
+
message,
|
|
667
|
+
waasProvider,
|
|
668
|
+
walletAccount
|
|
669
|
+
}, dynamicClient);
|
|
670
|
+
};
|
|
671
|
+
const signRawMessage$1 = async (args) => signRawMessage({
|
|
672
|
+
...args,
|
|
673
|
+
waasProvider
|
|
674
|
+
}, dynamicClient);
|
|
675
|
+
const signSerializedTransaction = async (args) => {
|
|
676
|
+
if (isBusinessAccountWalletAccount(args.walletAccount)) throw new TempoBusinessAccountTransactionNotSupportedError();
|
|
677
|
+
return await waasProvider.signSerializedTransaction(args);
|
|
678
|
+
};
|
|
679
|
+
const switchActiveNetwork = async ({ networkId }) => {
|
|
680
|
+
if (!require_tempoChainIds.isTempoChainId(networkId)) throw new InvalidTempoNetworkError({ networkId });
|
|
681
|
+
await (0, _dynamic_labs_sdk_client_core.switchActiveNetworkInLastKnownRegistry)({
|
|
682
|
+
client: dynamicClient,
|
|
683
|
+
networkId,
|
|
684
|
+
walletProviderKey: key
|
|
685
|
+
});
|
|
686
|
+
};
|
|
687
|
+
const destroy = (args) => waasProvider.destroy(args);
|
|
688
|
+
return {
|
|
689
|
+
...waasProvider,
|
|
690
|
+
chain,
|
|
691
|
+
confirmTransaction: (args) => tempoConfirmTransaction(args, dynamicClient),
|
|
692
|
+
createViemWalletClient,
|
|
693
|
+
destroy,
|
|
694
|
+
getActiveNetworkId,
|
|
695
|
+
getConnectedAddresses,
|
|
696
|
+
groupKey: (0, _dynamic_labs_sdk_client_core.formatWalletProviderGroupKey)(_dynamic_labs_sdk_client_waas_core.DYNAMIC_WAAS_METADATA.displayName),
|
|
697
|
+
key,
|
|
698
|
+
metadata: {
|
|
699
|
+
displayName: _dynamic_labs_sdk_client_waas_core.DYNAMIC_WAAS_METADATA.displayName,
|
|
700
|
+
icon: _dynamic_labs_sdk_client_waas_core.DYNAMIC_WAAS_METADATA.icon
|
|
701
|
+
},
|
|
702
|
+
signMessage: signMessage$1,
|
|
703
|
+
signRawMessage: signRawMessage$1,
|
|
704
|
+
signSerializedTransaction,
|
|
705
|
+
supportsFeeTokenSelection: true,
|
|
706
|
+
switchActiveNetwork,
|
|
707
|
+
transferAmount: (args) => tempoTransferAmount({
|
|
708
|
+
...args,
|
|
709
|
+
createViemWalletClient
|
|
710
|
+
}),
|
|
711
|
+
walletProviderType
|
|
712
|
+
};
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
//#endregion
|
|
716
|
+
//#region src/waas/addWaasTempoExtension/addWaasTempoExtension.ts
|
|
717
|
+
/** Registry key for the Tempo embedded wallet extension registered by addWaasTempoExtension. */
|
|
718
|
+
const WAAS_TEMPO_EXTENSION_KEY = "waasTempo";
|
|
719
|
+
/**
|
|
720
|
+
* Registers Tempo embedded wallet support with the Dynamic client: the Tempo
|
|
721
|
+
* network provider and the embedded wallet provider for Tempo.
|
|
722
|
+
* Calling it more than once is safe: later calls do nothing.
|
|
723
|
+
*
|
|
724
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple clients.
|
|
725
|
+
* @returns Nothing. The extension is registered on the client.
|
|
726
|
+
* @example
|
|
727
|
+
* ```ts
|
|
728
|
+
* import { addWaasTempoExtension } from '@dynamic-labs-sdk/tempo/waas';
|
|
729
|
+
*
|
|
730
|
+
* addWaasTempoExtension(dynamicClient);
|
|
731
|
+
* ```
|
|
732
|
+
* @see addTempoExtension
|
|
733
|
+
* @see isTempoWalletAccount
|
|
734
|
+
* @notInstrumented
|
|
735
|
+
*/
|
|
736
|
+
const addWaasTempoExtension = (client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
|
|
737
|
+
if ((0, _dynamic_labs_sdk_client_core.hasExtension)({ extensionKey: WAAS_TEMPO_EXTENSION_KEY }, client)) return;
|
|
738
|
+
(0, _dynamic_labs_sdk_client_core.registerExtension)({ extensionKey: WAAS_TEMPO_EXTENSION_KEY }, client);
|
|
739
|
+
require_tempoChainIds.registerTempoNetworkProviderBuilder(client);
|
|
740
|
+
const walletProviderRegistry = (0, _dynamic_labs_sdk_client_core.getWalletProviderRegistry)(client);
|
|
741
|
+
const walletProvider = createWalletProviderForWaasTempo({ dynamicClient: client });
|
|
742
|
+
walletProviderRegistry.register({
|
|
743
|
+
priority: _dynamic_labs_sdk_client_core.WalletProviderPriority.WALLET_SDK,
|
|
744
|
+
walletProvider
|
|
745
|
+
});
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
//#endregion
|
|
749
|
+
//#region src/exports/waas.ts
|
|
750
|
+
(0, _dynamic_labs_sdk_assert_package_version.assertPackageVersion)(require_tempoChainIds.name, require_tempoChainIds.version);
|
|
751
|
+
|
|
752
|
+
//#endregion
|
|
753
|
+
exports.InvalidTempoNetworkError = InvalidTempoNetworkError;
|
|
754
|
+
exports.TempoTransactionValidationError = TempoTransactionValidationError;
|
|
755
|
+
exports.TempoTypedDataNotSupportedError = TempoTypedDataNotSupportedError;
|
|
756
|
+
exports.addWaasTempoExtension = addWaasTempoExtension;
|
|
757
|
+
exports.sendTempoTransaction = sendTempoTransaction;
|
|
758
|
+
//# sourceMappingURL=waas.cjs.map
|