@dynamic-labs-wallet/evm 0.0.354 → 0.1.0-request-signing

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/index.cjs CHANGED
@@ -4,6 +4,7 @@ var browser = require('@dynamic-labs-wallet/browser');
4
4
  var viem = require('viem');
5
5
  var accounts = require('viem/accounts');
6
6
  var chains = require('viem/chains');
7
+ var utils = require('viem/utils');
7
8
 
8
9
  function _extends() {
9
10
  _extends = Object.assign || function assign(target) {
@@ -36,15 +37,41 @@ const formatEVMMessage = (message_, logger)=>{
36
37
  }
37
38
  };
38
39
  const formatTypedData = (typedData)=>{
39
- return viem.hashTypedData(typedData).slice(2);
40
+ try {
41
+ return viem.hashTypedData(typedData).slice(2);
42
+ } catch (error) {
43
+ // hashTypedData throws opaque errors (e.g. "Cannot read properties of
44
+ // undefined (reading 'length')") when `message` doesn't match `types`.
45
+ // Re-throw with a clear, actionable message identifying the typedData as
46
+ // the cause. Two cases:
47
+ // 1) format issues (bad address, int out of range, wrong bytes size,
48
+ // invalid primaryType/struct) -> viem's validateTypedData pinpoints it.
49
+ // 2) a field declared in `types` is missing/undefined in `message`
50
+ // (incl. primitive `string`/`bytes`) -> validateTypedData does NOT
51
+ // flag this, so we surface it explicitly here.
52
+ const primaryType = typedData.primaryType;
53
+ try {
54
+ viem.validateTypedData(typedData);
55
+ } catch (validationError) {
56
+ throw Object.assign(new Error(`Invalid EIP-712 typedData: ${validationError.message}`), {
57
+ cause: error
58
+ });
59
+ }
60
+ const primaryTypeSuffix = primaryType ? ` (primaryType "${primaryType}")` : '';
61
+ const message = `Invalid EIP-712 typedData: a field declared in \`types\` is missing or ` + `undefined in \`message\`${primaryTypeSuffix}. ` + `Every field declared in \`types\` must be present in \`message\`. ` + `Underlying error: ${error.message}`;
62
+ throw Object.assign(new Error(message), {
63
+ cause: error
64
+ });
65
+ }
40
66
  };
67
+ const serializeEcdsaSignature = (signature)=>viem.serializeSignature({
68
+ r: `0x${Buffer.from(signature.r).toString('hex')}`,
69
+ s: `0x${Buffer.from(signature.s).toString('hex')}`,
70
+ v: BigInt(signature.v)
71
+ });
41
72
  const serializeECDSASignature = (signature, logger)=>{
42
73
  try {
43
- return viem.serializeSignature({
44
- r: `0x${Buffer.from(signature.r).toString('hex')}`,
45
- s: `0x${Buffer.from(signature.s).toString('hex')}`,
46
- v: BigInt(signature.v)
47
- });
74
+ return serializeEcdsaSignature(signature);
48
75
  } catch (error) {
49
76
  logger.error('[DynamicWaasWalletClient]: Error serializing ECDSA signature:', error);
50
77
  throw error;
@@ -53,7 +80,7 @@ const serializeECDSASignature = (signature, logger)=>{
53
80
 
54
81
  const checkRawPublicKeyInstance = (rawPublicKey)=>{
55
82
  if (!(rawPublicKey instanceof browser.EcdsaPublicKey)) {
56
- throw new Error('Invalid raw public key');
83
+ throw new TypeError('Invalid raw public key');
57
84
  }
58
85
  };
59
86
  const mapTransactionToEvmTransaction = (transaction)=>{
@@ -78,7 +105,11 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
78
105
  transport: viem.http(rpcUrl)
79
106
  });
80
107
  }
81
- async createWalletAccount({ thresholdSignatureScheme, password = undefined, onError, signedSessionId, traceContext }) {
108
+ /**
109
+ * Create an EVM wallet. When `businessAccountId` is passed the wallet is
110
+ * owned by that business account and redcoast creates the signer row mapping
111
+ * the new share set — same keygen + backup ceremony and endpoints either way.
112
+ */ async createWalletAccount({ thresholdSignatureScheme, password = undefined, onError, signedSessionId, traceContext, businessAccountId }) {
82
113
  try {
83
114
  // Create a promise that will resolve when the ceremony is complete
84
115
  let ceremonyCeremonyCompleteResolver;
@@ -89,11 +120,12 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
89
120
  const { rawPublicKey, clientKeyShares } = await this.keyGen({
90
121
  chainName: this.chainName,
91
122
  thresholdSignatureScheme,
123
+ businessAccountId,
92
124
  onError: (error)=>{
93
125
  this.logger.error(browser.ERROR_CREATE_WALLET_ACCOUNT, error);
94
126
  onError == null ? void 0 : onError(error);
95
127
  },
96
- onCeremonyComplete: (accountAddress, walletId, shareSetId)=>{
128
+ onCeremonyComplete: ({ accountAddress, walletId, shareSetId })=>{
97
129
  const checksumAddress = viem.getAddress(accountAddress);
98
130
  const chainConfig = browser.getMPCChainConfig(this.chainName);
99
131
  this.initializeWalletMapEntry({
@@ -119,7 +151,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
119
151
  throw new Error(browser.ERROR_KEYGEN_FAILED);
120
152
  }
121
153
  checkRawPublicKeyInstance(rawPublicKey);
122
- const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
154
+ const { accountAddress, publicKeyHex } = this.deriveAccountAddress({
123
155
  rawPublicKey: rawPublicKey
124
156
  });
125
157
  // Update client key shares in wallet map
@@ -131,7 +163,8 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
131
163
  accountAddress,
132
164
  clientKeyShares,
133
165
  password,
134
- signedSessionId
166
+ signedSessionId,
167
+ businessAccountId
135
168
  });
136
169
  return {
137
170
  accountAddress,
@@ -139,15 +172,17 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
139
172
  publicKeyHex
140
173
  };
141
174
  } catch (error) {
142
- // Re-throw password mismatch errors without wrapping
143
- if (error instanceof Error && error.message === browser.ERROR_PASSWORD_MISMATCH) {
175
+ // Re-throw known business-rule rejections without wrapping
176
+ if (error instanceof Error && (error.message === browser.ERROR_PASSWORD_MISMATCH || error.message === browser.ERROR_MULTIPLE_WALLETS_PER_CHAIN)) {
144
177
  throw error;
145
178
  }
146
179
  this.logger.error(browser.ERROR_CREATE_WALLET_ACCOUNT, error);
147
- throw new Error(browser.ERROR_CREATE_WALLET_ACCOUNT);
180
+ throw new Error(browser.ERROR_CREATE_WALLET_ACCOUNT, {
181
+ cause: error
182
+ });
148
183
  }
149
184
  }
150
- async signMessage({ message, accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, context, onError, traceContext }) {
185
+ async signMessage({ message, accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, context, approvalQuorum, onError, traceContext }) {
151
186
  await this.verifyPassword({
152
187
  accountAddress,
153
188
  password,
@@ -158,7 +193,9 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
158
193
  throw new Error(browser.ERROR_ACCOUNT_ADDRESS_REQUIRED);
159
194
  }
160
195
  // Format the message for EVM signing
161
- const formattedMessage = formatEVMMessage(message, this.logger);
196
+ const formattedMessage = this.prepareSignMessage({
197
+ message
198
+ });
162
199
  const resolvedContext = context != null ? context : {
163
200
  evmMessage: message
164
201
  };
@@ -172,6 +209,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
172
209
  mfaToken,
173
210
  elevatedAccessToken,
174
211
  context: resolvedContext,
212
+ approvalQuorum,
175
213
  onError,
176
214
  traceContext
177
215
  });
@@ -179,10 +217,15 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
179
217
  const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
180
218
  return serializedSignature;
181
219
  } catch (error) {
182
- this.logger.error(browser.ERROR_SIGN_MESSAGE, error);
183
- throw new Error(browser.ERROR_SIGN_MESSAGE);
220
+ this.logOperationFailure(browser.ERROR_SIGN_MESSAGE, error);
221
+ throw new Error(browser.ERROR_SIGN_MESSAGE, {
222
+ cause: error
223
+ });
184
224
  }
185
225
  }
226
+ prepareSignMessage({ message }) {
227
+ return formatEVMMessage(message, this.logger);
228
+ }
186
229
  async verifyMessageSignature({ accountAddress, message, signature }) {
187
230
  try {
188
231
  // Verify the signature using the public client
@@ -200,13 +243,21 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
200
243
  throw new Error(browser.ERROR_VERIFY_MESSAGE_SIGNATURE);
201
244
  }
202
245
  }
203
- async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, context, onError, traceContext }) {
246
+ prepareSignTransaction({ transaction }) {
247
+ return viem.serializeTransaction(transaction);
248
+ }
249
+ prepareSignTypedData({ typedData }) {
250
+ return formatTypedData(typedData);
251
+ }
252
+ async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, context, approvalQuorum, onError, traceContext }) {
204
253
  await this.verifyPassword({
205
254
  accountAddress: senderAddress,
206
255
  password,
207
256
  signedSessionId
208
257
  });
209
- const serializedTx = viem.serializeTransaction(transaction);
258
+ const serializedTx = this.prepareSignTransaction({
259
+ transaction
260
+ });
210
261
  const serializedTxBytes = Uint8Array.from(Buffer.from(serializedTx.slice(2), 'hex'));
211
262
  if (!(serializedTxBytes instanceof Uint8Array)) {
212
263
  throw new Error('Invalid serializedTxBytes');
@@ -223,6 +274,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
223
274
  context: _extends({}, context, {
224
275
  evmTransaction: mapTransactionToEvmTransaction(transaction)
225
276
  }),
277
+ approvalQuorum,
226
278
  onError,
227
279
  traceContext
228
280
  });
@@ -244,7 +296,45 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
244
296
  throw error;
245
297
  }
246
298
  }
247
- async signTypedData({ accountAddress, typedData, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, onError, traceContext }) {
299
+ /**
300
+ * Signs the transaction for Dynamic to broadcast.
301
+ *
302
+ * @param params.senderAddress - The wallet's address.
303
+ * @param params.transaction - The transaction, with its fee: `gasPrice`, or `maxFeePerGas` with `maxPriorityFeePerGas`.
304
+ * @param params.requestedCertainty - How sure to be before calling it confirmed: `fast`, `safe` or `final`, or `chain:` plus a chain-specific value. Defaults to `safe`.
305
+ * @param params.externalReference - Your own label, returned on every event. Not unique.
306
+ * @param params.idempotencyKey - Makes a retry safe: the same key replays the stored answer instead of sending twice. A new one is made when omitted.
307
+ * @param params.password - The wallet's backup password, if it has one.
308
+ * @param params.signedSessionId - The signed-in session, used to unlock the wallet's key share.
309
+ * @param params.mfaToken - Proof of the user's multi-factor check, when the wallet needs one.
310
+ * @param params.elevatedAccessToken - Proof of a recent re-login, when the wallet needs one.
311
+ * @param params.approvalQuorum - Approvers' consent for a governed wallet, sent on the retry after `intent_required`.
312
+ * @param params.onError - Called with the failure's message, never the raw error.
313
+ * @param params.traceContext - Ties this call's logs to the server's, across retries. Created when omitted.
314
+ * @returns The transaction record.
315
+ */ async signAndBroadcastTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, approvalQuorum, requestedCertainty, externalReference, idempotencyKey, onError, traceContext }) {
316
+ return await this.signAndBroadcast({
317
+ accountAddress: senderAddress,
318
+ chainName: this.chainName,
319
+ context: {
320
+ evmTransaction: mapTransactionToEvmTransaction(transaction)
321
+ },
322
+ message: this.prepareSignTransaction({
323
+ transaction: transaction
324
+ }),
325
+ password,
326
+ signedSessionId,
327
+ mfaToken,
328
+ elevatedAccessToken,
329
+ approvalQuorum,
330
+ requestedCertainty,
331
+ externalReference,
332
+ idempotencyKey,
333
+ onError,
334
+ traceContext
335
+ });
336
+ }
337
+ async signTypedData({ accountAddress, typedData, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, approvalQuorum, onError, traceContext }) {
248
338
  await this.verifyPassword({
249
339
  accountAddress,
250
340
  password,
@@ -254,7 +344,9 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
254
344
  if (!accountAddress) {
255
345
  throw new Error(browser.ERROR_ACCOUNT_ADDRESS_REQUIRED);
256
346
  }
257
- const formattedTypedData = formatTypedData(typedData);
347
+ const formattedTypedData = this.prepareSignTypedData({
348
+ typedData
349
+ });
258
350
  const signatureEcdsa = await this.sign({
259
351
  message: formattedTypedData,
260
352
  accountAddress: accountAddress,
@@ -267,14 +359,17 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
267
359
  context: {
268
360
  evmTypedData: typedData
269
361
  },
362
+ approvalQuorum,
270
363
  onError,
271
364
  traceContext
272
365
  });
273
366
  const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
274
367
  return serializedSignature;
275
368
  } catch (error) {
276
- this.logger.error(browser.ERROR_SIGN_TYPED_DATA, error);
277
- throw new Error(browser.ERROR_SIGN_TYPED_DATA);
369
+ this.logOperationFailure(browser.ERROR_SIGN_TYPED_DATA, error);
370
+ throw new Error(browser.ERROR_SIGN_TYPED_DATA, {
371
+ cause: error
372
+ });
278
373
  }
279
374
  }
280
375
  deriveAccountAddress({ rawPublicKey }) {
@@ -289,7 +384,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
289
384
  publicKeyHex
290
385
  };
291
386
  }
292
- async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, traceContext }) {
387
+ async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, approvalQuorum, proposalId, traceContext }) {
293
388
  await this.verifyPassword({
294
389
  accountAddress,
295
390
  password,
@@ -302,6 +397,8 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
302
397
  signedSessionId,
303
398
  mfaToken,
304
399
  elevatedAccessToken,
400
+ approvalQuorum,
401
+ proposalId,
305
402
  traceContext
306
403
  });
307
404
  return derivedPrivateKey;
@@ -334,7 +431,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
334
431
  chainName,
335
432
  privateKey: formattedPrivateKey,
336
433
  thresholdSignatureScheme,
337
- onCeremonyComplete: (accountAddress, walletId, shareSetId)=>{
434
+ onCeremonyComplete: ({ accountAddress, walletId, shareSetId })=>{
338
435
  const checksumAddress = viem.getAddress(accountAddress);
339
436
  this.initializeWalletMapEntry({
340
437
  accountAddress: checksumAddress,
@@ -356,7 +453,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
356
453
  throw new Error(browser.ERROR_IMPORT_PRIVATE_KEY);
357
454
  }
358
455
  checkRawPublicKeyInstance(rawPublicKey);
359
- const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
456
+ const { accountAddress, publicKeyHex } = this.deriveAccountAddress({
360
457
  rawPublicKey: rawPublicKey
361
458
  });
362
459
  // Update client key shares in wallet map
@@ -386,22 +483,162 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
386
483
  const evmWallets = wallets.filter((wallet)=>wallet.chainName === 'EVM');
387
484
  return evmWallets;
388
485
  }
389
- constructor({ environmentId, authToken, backupServiceAuthToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode = browser.AuthMode.HEADER, sdkVersion, forwardMPCClient, logger }, internalOptions){
390
- super({
391
- environmentId,
392
- authToken,
393
- backupServiceAuthToken,
394
- baseApiUrl,
395
- baseMPCRelayApiUrl,
396
- storageKey,
397
- debug,
398
- featureFlags,
399
- authMode,
400
- sdkVersion,
401
- forwardMPCClient,
402
- logger
403
- }, internalOptions), this.chainName = 'EVM';
486
+ constructor(...args){
487
+ super(...args), this.chainName = 'EVM';
404
488
  }
405
489
  }
406
490
 
491
+ const decimal = (value)=>BigInt(value).toString(10);
492
+ const parseLimit = (value, name)=>{
493
+ if (!/^(0|[1-9]\d*)$/.test(value)) throw new Error(`Invalid ${name} signing limit`);
494
+ return BigInt(value);
495
+ };
496
+ const parseLimits = (limits)=>({
497
+ maxGas: parseLimit(limits.maxGas, 'maxGas'),
498
+ maxFeePerGas: parseLimit(limits.maxFeePerGas, 'maxFeePerGas'),
499
+ maxPriorityFeePerGas: parseLimit(limits.maxPriorityFeePerGas, 'maxPriorityFeePerGas'),
500
+ maxTotalFee: parseLimit(limits.maxTotalFee, 'maxTotalFee')
501
+ });
502
+ const prepareEvmTransactionSigningOperation = ({ transaction, accountAddress, refreshLimits, refreshableNonce = false })=>{
503
+ var _parsed_accessList;
504
+ const parsed = viem.parseTransaction(transaction);
505
+ var _parsed_accessList_length;
506
+ if (parsed.type !== 'eip1559' || ((_parsed_accessList_length = (_parsed_accessList = parsed.accessList) == null ? void 0 : _parsed_accessList.length) != null ? _parsed_accessList_length : 0) !== 0) {
507
+ throw new Error('Signing intent supports only EIP-1559 transactions with an empty access list');
508
+ }
509
+ const { chainId, nonce, gas, maxFeePerGas } = parsed;
510
+ var _parsed_maxPriorityFeePerGas;
511
+ // viem drops zero-valued fee fields when parsing, so an absent tip is a valid zero tip.
512
+ const maxPriorityFeePerGas = (_parsed_maxPriorityFeePerGas = parsed.maxPriorityFeePerGas) != null ? _parsed_maxPriorityFeePerGas : 0n;
513
+ if (nonce === undefined || gas === undefined || maxFeePerGas === undefined || parsed.yParity !== undefined || parsed.r !== undefined || parsed.s !== undefined) {
514
+ throw new Error('Signing intent requires a complete unsigned EIP-1559 transaction');
515
+ }
516
+ if (gas === 0n || maxFeePerGas === 0n) {
517
+ throw new Error('Transaction gas and maximum fee must be positive');
518
+ }
519
+ const limits = refreshLimits != null ? refreshLimits : {
520
+ maxGas: decimal(gas),
521
+ maxFeePerGas: decimal(maxFeePerGas),
522
+ maxPriorityFeePerGas: decimal(maxPriorityFeePerGas),
523
+ maxTotalFee: decimal(gas * maxFeePerGas)
524
+ };
525
+ const parsedLimits = parseLimits(limits);
526
+ if (parsedLimits.maxGas < gas || parsedLimits.maxFeePerGas < maxFeePerGas || parsedLimits.maxPriorityFeePerGas < maxPriorityFeePerGas || parsedLimits.maxPriorityFeePerGas > parsedLimits.maxFeePerGas || gas * maxFeePerGas > parsedLimits.maxTotalFee) {
527
+ throw new Error('Transaction exceeds signing intent limits');
528
+ }
529
+ var _parsed_value, _parsed_data;
530
+ const prepared = {
531
+ operation: {
532
+ kind: 'transaction',
533
+ chainName: 'EVM',
534
+ chainId: decimal(chainId),
535
+ from: viem.getAddress(accountAddress).toLowerCase(),
536
+ to: parsed.to ? viem.getAddress(parsed.to).toLowerCase() : null,
537
+ value: decimal((_parsed_value = parsed.value) != null ? _parsed_value : 0n),
538
+ data: ((_parsed_data = parsed.data) != null ? _parsed_data : '0x').toLowerCase(),
539
+ nonce: decimal(nonce)
540
+ },
541
+ limits
542
+ };
543
+ if (refreshableNonce) prepared.lifetime = {
544
+ refreshable: 'nonce'
545
+ };
546
+ return prepared;
547
+ };
548
+ const safeNumber = (value, name)=>{
549
+ const parsed = parseLimit(value, name);
550
+ if (parsed > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error(`Invalid ${name} signing value`);
551
+ return Number(parsed);
552
+ };
553
+ /** The authorization is hashed from JS numbers, so a chain id or nonce must be an exact, in-range integer. */ const assertValidEip7702Auth = (eip7702Auth)=>{
554
+ if (!Number.isSafeInteger(eip7702Auth.chainId) || eip7702Auth.chainId <= 0) {
555
+ throw new Error('Invalid chainId signing value');
556
+ }
557
+ if (!Number.isSafeInteger(eip7702Auth.nonce) || eip7702Auth.nonce < 0) {
558
+ throw new Error('Invalid nonce signing value');
559
+ }
560
+ viem.getAddress(eip7702Auth.address);
561
+ };
562
+ /**
563
+ * Builds the intent operation for an EIP-7702 authorization; `payload` is the hash the wallet signs.
564
+ * The authorization is carried unchanged so it can be compared with the sign request's context.
565
+ */ const prepareEip7702AuthSigningOperation = ({ eip7702Auth })=>{
566
+ assertValidEip7702Auth(eip7702Auth);
567
+ const { address, chainId, nonce } = eip7702Auth;
568
+ return {
569
+ operation: {
570
+ kind: 'eip7702Auth',
571
+ chainName: 'EVM',
572
+ eip7702Auth: {
573
+ address,
574
+ chainId,
575
+ nonce
576
+ },
577
+ payload: utils.hashAuthorization({
578
+ chainId,
579
+ contractAddress: address,
580
+ nonce
581
+ }).slice(2)
582
+ }
583
+ };
584
+ };
585
+ /** Reads an approved operation's authorization, rejecting a zero, negative or unsafe chain id or nonce. */ const eip7702AuthorizationFromOperation = ({ operation })=>{
586
+ assertValidEip7702Auth(operation.eip7702Auth);
587
+ return operation.eip7702Auth;
588
+ };
589
+ /**
590
+ * Reconstructs an unsigned EIP-1559 transaction from an approved intent.
591
+ * Only gas and fee values may change, within the approved limits, plus the
592
+ * nonce when the intent signed a refreshable nonce. That nonce (`lifetimeValue`,
593
+ * decimal) is optional: without it, the nonce from the signed operation is used.
594
+ */ const resumeEvmTransactionSigningIntent = ({ intent, lifetimeValue })=>{
595
+ var _intent_lifetime;
596
+ if (intent.operation.kind !== 'transaction' || intent.operation.chainName !== 'EVM' || !intent.limits) {
597
+ throw new Error('Stored signing intent is not an EVM transaction');
598
+ }
599
+ const refreshableNonce = ((_intent_lifetime = intent.lifetime) == null ? void 0 : _intent_lifetime.refreshable) === 'nonce';
600
+ if (lifetimeValue !== undefined && !refreshableNonce) {
601
+ throw new Error('A nonce can be supplied only when the EVM transaction intent has a refreshable nonce');
602
+ }
603
+ const nonce = lifetimeValue != null ? lifetimeValue : intent.operation.nonce;
604
+ const { operation, limits } = intent;
605
+ const parsedLimits = parseLimits(limits);
606
+ if (parsedLimits.maxGas === 0n || parsedLimits.maxFeePerGas === 0n) {
607
+ throw new Error('Stored EVM transaction intent has unusable fee limits');
608
+ }
609
+ const gas = parsedLimits.maxGas;
610
+ // The signed total-fee ceiling can be tighter than the independent gas and
611
+ // fee ceilings, so derive the largest fee cap that satisfies all three.
612
+ const maxFeePerGas = parsedLimits.maxTotalFee / gas < parsedLimits.maxFeePerGas ? parsedLimits.maxTotalFee / gas : parsedLimits.maxFeePerGas;
613
+ if (maxFeePerGas === 0n) {
614
+ throw new Error('Stored EVM transaction intent has unusable fee limits');
615
+ }
616
+ const maxPriorityFeePerGas = parsedLimits.maxPriorityFeePerGas < maxFeePerGas ? parsedLimits.maxPriorityFeePerGas : maxFeePerGas;
617
+ const transaction = viem.serializeTransaction({
618
+ chainId: safeNumber(operation.chainId, 'chainId'),
619
+ data: operation.data,
620
+ gas,
621
+ maxFeePerGas,
622
+ maxPriorityFeePerGas,
623
+ nonce: safeNumber(nonce, 'nonce'),
624
+ to: operation.to ? viem.getAddress(operation.to) : undefined,
625
+ type: 'eip1559',
626
+ value: parseLimit(operation.value, 'value')
627
+ });
628
+ const reconstructed = prepareEvmTransactionSigningOperation({
629
+ accountAddress: intent.accountAddress,
630
+ refreshLimits: limits,
631
+ transaction
632
+ });
633
+ if (reconstructed.operation.chainId !== operation.chainId || reconstructed.operation.from !== operation.from || reconstructed.operation.to !== operation.to || reconstructed.operation.value !== operation.value || reconstructed.operation.data !== operation.data || reconstructed.operation.nonce !== nonce) {
634
+ throw new Error('Stored EVM transaction intent is malformed');
635
+ }
636
+ return transaction;
637
+ };
638
+
407
639
  exports.DynamicEvmWalletClient = DynamicEvmWalletClient;
640
+ exports.eip7702AuthorizationFromOperation = eip7702AuthorizationFromOperation;
641
+ exports.prepareEip7702AuthSigningOperation = prepareEip7702AuthSigningOperation;
642
+ exports.prepareEvmTransactionSigningOperation = prepareEvmTransactionSigningOperation;
643
+ exports.resumeEvmTransactionSigningIntent = resumeEvmTransactionSigningIntent;
644
+ exports.serializeEcdsaSignature = serializeEcdsaSignature;
package/index.esm.js CHANGED
@@ -1,7 +1,8 @@
1
- import { EcdsaPublicKey, DynamicWalletClient, getMPCChainConfig, ERROR_CREATE_WALLET_ACCOUNT, ERROR_KEYGEN_FAILED, ERROR_PASSWORD_MISMATCH, ERROR_ACCOUNT_ADDRESS_REQUIRED, ERROR_SIGN_MESSAGE, ERROR_VERIFY_MESSAGE_SIGNATURE, ERROR_SIGN_TYPED_DATA, MessageHash, ERROR_IMPORT_PRIVATE_KEY, AuthMode } from '@dynamic-labs-wallet/browser';
2
- import { stringToHex, bytesToHex, size, concat, serializeSignature, hashTypedData, createPublicClient, http, getAddress, serializeTransaction } from 'viem';
1
+ import { EcdsaPublicKey, DynamicWalletClient, getMPCChainConfig, ERROR_CREATE_WALLET_ACCOUNT, ERROR_KEYGEN_FAILED, ERROR_PASSWORD_MISMATCH, ERROR_MULTIPLE_WALLETS_PER_CHAIN, ERROR_ACCOUNT_ADDRESS_REQUIRED, ERROR_SIGN_MESSAGE, ERROR_VERIFY_MESSAGE_SIGNATURE, ERROR_SIGN_TYPED_DATA, MessageHash, ERROR_IMPORT_PRIVATE_KEY } from '@dynamic-labs-wallet/browser';
2
+ import { serializeSignature, stringToHex, bytesToHex, size, concat, hashTypedData, validateTypedData, createPublicClient, http, getAddress, serializeTransaction, parseTransaction } from 'viem';
3
3
  import { privateKeyToAccount } from 'viem/accounts';
4
4
  import { mainnet } from 'viem/chains';
5
+ import { hashAuthorization } from 'viem/utils';
5
6
 
6
7
  function _extends() {
7
8
  _extends = Object.assign || function assign(target) {
@@ -34,15 +35,41 @@ const formatEVMMessage = (message_, logger)=>{
34
35
  }
35
36
  };
36
37
  const formatTypedData = (typedData)=>{
37
- return hashTypedData(typedData).slice(2);
38
+ try {
39
+ return hashTypedData(typedData).slice(2);
40
+ } catch (error) {
41
+ // hashTypedData throws opaque errors (e.g. "Cannot read properties of
42
+ // undefined (reading 'length')") when `message` doesn't match `types`.
43
+ // Re-throw with a clear, actionable message identifying the typedData as
44
+ // the cause. Two cases:
45
+ // 1) format issues (bad address, int out of range, wrong bytes size,
46
+ // invalid primaryType/struct) -> viem's validateTypedData pinpoints it.
47
+ // 2) a field declared in `types` is missing/undefined in `message`
48
+ // (incl. primitive `string`/`bytes`) -> validateTypedData does NOT
49
+ // flag this, so we surface it explicitly here.
50
+ const primaryType = typedData.primaryType;
51
+ try {
52
+ validateTypedData(typedData);
53
+ } catch (validationError) {
54
+ throw Object.assign(new Error(`Invalid EIP-712 typedData: ${validationError.message}`), {
55
+ cause: error
56
+ });
57
+ }
58
+ const primaryTypeSuffix = primaryType ? ` (primaryType "${primaryType}")` : '';
59
+ const message = `Invalid EIP-712 typedData: a field declared in \`types\` is missing or ` + `undefined in \`message\`${primaryTypeSuffix}. ` + `Every field declared in \`types\` must be present in \`message\`. ` + `Underlying error: ${error.message}`;
60
+ throw Object.assign(new Error(message), {
61
+ cause: error
62
+ });
63
+ }
38
64
  };
65
+ const serializeEcdsaSignature = (signature)=>serializeSignature({
66
+ r: `0x${Buffer.from(signature.r).toString('hex')}`,
67
+ s: `0x${Buffer.from(signature.s).toString('hex')}`,
68
+ v: BigInt(signature.v)
69
+ });
39
70
  const serializeECDSASignature = (signature, logger)=>{
40
71
  try {
41
- return serializeSignature({
42
- r: `0x${Buffer.from(signature.r).toString('hex')}`,
43
- s: `0x${Buffer.from(signature.s).toString('hex')}`,
44
- v: BigInt(signature.v)
45
- });
72
+ return serializeEcdsaSignature(signature);
46
73
  } catch (error) {
47
74
  logger.error('[DynamicWaasWalletClient]: Error serializing ECDSA signature:', error);
48
75
  throw error;
@@ -51,7 +78,7 @@ const serializeECDSASignature = (signature, logger)=>{
51
78
 
52
79
  const checkRawPublicKeyInstance = (rawPublicKey)=>{
53
80
  if (!(rawPublicKey instanceof EcdsaPublicKey)) {
54
- throw new Error('Invalid raw public key');
81
+ throw new TypeError('Invalid raw public key');
55
82
  }
56
83
  };
57
84
  const mapTransactionToEvmTransaction = (transaction)=>{
@@ -76,7 +103,11 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
76
103
  transport: http(rpcUrl)
77
104
  });
78
105
  }
79
- async createWalletAccount({ thresholdSignatureScheme, password = undefined, onError, signedSessionId, traceContext }) {
106
+ /**
107
+ * Create an EVM wallet. When `businessAccountId` is passed the wallet is
108
+ * owned by that business account and redcoast creates the signer row mapping
109
+ * the new share set — same keygen + backup ceremony and endpoints either way.
110
+ */ async createWalletAccount({ thresholdSignatureScheme, password = undefined, onError, signedSessionId, traceContext, businessAccountId }) {
80
111
  try {
81
112
  // Create a promise that will resolve when the ceremony is complete
82
113
  let ceremonyCeremonyCompleteResolver;
@@ -87,11 +118,12 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
87
118
  const { rawPublicKey, clientKeyShares } = await this.keyGen({
88
119
  chainName: this.chainName,
89
120
  thresholdSignatureScheme,
121
+ businessAccountId,
90
122
  onError: (error)=>{
91
123
  this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
92
124
  onError == null ? void 0 : onError(error);
93
125
  },
94
- onCeremonyComplete: (accountAddress, walletId, shareSetId)=>{
126
+ onCeremonyComplete: ({ accountAddress, walletId, shareSetId })=>{
95
127
  const checksumAddress = getAddress(accountAddress);
96
128
  const chainConfig = getMPCChainConfig(this.chainName);
97
129
  this.initializeWalletMapEntry({
@@ -117,7 +149,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
117
149
  throw new Error(ERROR_KEYGEN_FAILED);
118
150
  }
119
151
  checkRawPublicKeyInstance(rawPublicKey);
120
- const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
152
+ const { accountAddress, publicKeyHex } = this.deriveAccountAddress({
121
153
  rawPublicKey: rawPublicKey
122
154
  });
123
155
  // Update client key shares in wallet map
@@ -129,7 +161,8 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
129
161
  accountAddress,
130
162
  clientKeyShares,
131
163
  password,
132
- signedSessionId
164
+ signedSessionId,
165
+ businessAccountId
133
166
  });
134
167
  return {
135
168
  accountAddress,
@@ -137,15 +170,17 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
137
170
  publicKeyHex
138
171
  };
139
172
  } catch (error) {
140
- // Re-throw password mismatch errors without wrapping
141
- if (error instanceof Error && error.message === ERROR_PASSWORD_MISMATCH) {
173
+ // Re-throw known business-rule rejections without wrapping
174
+ if (error instanceof Error && (error.message === ERROR_PASSWORD_MISMATCH || error.message === ERROR_MULTIPLE_WALLETS_PER_CHAIN)) {
142
175
  throw error;
143
176
  }
144
177
  this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
145
- throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
178
+ throw new Error(ERROR_CREATE_WALLET_ACCOUNT, {
179
+ cause: error
180
+ });
146
181
  }
147
182
  }
148
- async signMessage({ message, accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, context, onError, traceContext }) {
183
+ async signMessage({ message, accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, context, approvalQuorum, onError, traceContext }) {
149
184
  await this.verifyPassword({
150
185
  accountAddress,
151
186
  password,
@@ -156,7 +191,9 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
156
191
  throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
157
192
  }
158
193
  // Format the message for EVM signing
159
- const formattedMessage = formatEVMMessage(message, this.logger);
194
+ const formattedMessage = this.prepareSignMessage({
195
+ message
196
+ });
160
197
  const resolvedContext = context != null ? context : {
161
198
  evmMessage: message
162
199
  };
@@ -170,6 +207,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
170
207
  mfaToken,
171
208
  elevatedAccessToken,
172
209
  context: resolvedContext,
210
+ approvalQuorum,
173
211
  onError,
174
212
  traceContext
175
213
  });
@@ -177,10 +215,15 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
177
215
  const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
178
216
  return serializedSignature;
179
217
  } catch (error) {
180
- this.logger.error(ERROR_SIGN_MESSAGE, error);
181
- throw new Error(ERROR_SIGN_MESSAGE);
218
+ this.logOperationFailure(ERROR_SIGN_MESSAGE, error);
219
+ throw new Error(ERROR_SIGN_MESSAGE, {
220
+ cause: error
221
+ });
182
222
  }
183
223
  }
224
+ prepareSignMessage({ message }) {
225
+ return formatEVMMessage(message, this.logger);
226
+ }
184
227
  async verifyMessageSignature({ accountAddress, message, signature }) {
185
228
  try {
186
229
  // Verify the signature using the public client
@@ -198,13 +241,21 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
198
241
  throw new Error(ERROR_VERIFY_MESSAGE_SIGNATURE);
199
242
  }
200
243
  }
201
- async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, context, onError, traceContext }) {
244
+ prepareSignTransaction({ transaction }) {
245
+ return serializeTransaction(transaction);
246
+ }
247
+ prepareSignTypedData({ typedData }) {
248
+ return formatTypedData(typedData);
249
+ }
250
+ async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, context, approvalQuorum, onError, traceContext }) {
202
251
  await this.verifyPassword({
203
252
  accountAddress: senderAddress,
204
253
  password,
205
254
  signedSessionId
206
255
  });
207
- const serializedTx = serializeTransaction(transaction);
256
+ const serializedTx = this.prepareSignTransaction({
257
+ transaction
258
+ });
208
259
  const serializedTxBytes = Uint8Array.from(Buffer.from(serializedTx.slice(2), 'hex'));
209
260
  if (!(serializedTxBytes instanceof Uint8Array)) {
210
261
  throw new Error('Invalid serializedTxBytes');
@@ -221,6 +272,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
221
272
  context: _extends({}, context, {
222
273
  evmTransaction: mapTransactionToEvmTransaction(transaction)
223
274
  }),
275
+ approvalQuorum,
224
276
  onError,
225
277
  traceContext
226
278
  });
@@ -242,7 +294,45 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
242
294
  throw error;
243
295
  }
244
296
  }
245
- async signTypedData({ accountAddress, typedData, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, onError, traceContext }) {
297
+ /**
298
+ * Signs the transaction for Dynamic to broadcast.
299
+ *
300
+ * @param params.senderAddress - The wallet's address.
301
+ * @param params.transaction - The transaction, with its fee: `gasPrice`, or `maxFeePerGas` with `maxPriorityFeePerGas`.
302
+ * @param params.requestedCertainty - How sure to be before calling it confirmed: `fast`, `safe` or `final`, or `chain:` plus a chain-specific value. Defaults to `safe`.
303
+ * @param params.externalReference - Your own label, returned on every event. Not unique.
304
+ * @param params.idempotencyKey - Makes a retry safe: the same key replays the stored answer instead of sending twice. A new one is made when omitted.
305
+ * @param params.password - The wallet's backup password, if it has one.
306
+ * @param params.signedSessionId - The signed-in session, used to unlock the wallet's key share.
307
+ * @param params.mfaToken - Proof of the user's multi-factor check, when the wallet needs one.
308
+ * @param params.elevatedAccessToken - Proof of a recent re-login, when the wallet needs one.
309
+ * @param params.approvalQuorum - Approvers' consent for a governed wallet, sent on the retry after `intent_required`.
310
+ * @param params.onError - Called with the failure's message, never the raw error.
311
+ * @param params.traceContext - Ties this call's logs to the server's, across retries. Created when omitted.
312
+ * @returns The transaction record.
313
+ */ async signAndBroadcastTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, approvalQuorum, requestedCertainty, externalReference, idempotencyKey, onError, traceContext }) {
314
+ return await this.signAndBroadcast({
315
+ accountAddress: senderAddress,
316
+ chainName: this.chainName,
317
+ context: {
318
+ evmTransaction: mapTransactionToEvmTransaction(transaction)
319
+ },
320
+ message: this.prepareSignTransaction({
321
+ transaction: transaction
322
+ }),
323
+ password,
324
+ signedSessionId,
325
+ mfaToken,
326
+ elevatedAccessToken,
327
+ approvalQuorum,
328
+ requestedCertainty,
329
+ externalReference,
330
+ idempotencyKey,
331
+ onError,
332
+ traceContext
333
+ });
334
+ }
335
+ async signTypedData({ accountAddress, typedData, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, approvalQuorum, onError, traceContext }) {
246
336
  await this.verifyPassword({
247
337
  accountAddress,
248
338
  password,
@@ -252,7 +342,9 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
252
342
  if (!accountAddress) {
253
343
  throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
254
344
  }
255
- const formattedTypedData = formatTypedData(typedData);
345
+ const formattedTypedData = this.prepareSignTypedData({
346
+ typedData
347
+ });
256
348
  const signatureEcdsa = await this.sign({
257
349
  message: formattedTypedData,
258
350
  accountAddress: accountAddress,
@@ -265,14 +357,17 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
265
357
  context: {
266
358
  evmTypedData: typedData
267
359
  },
360
+ approvalQuorum,
268
361
  onError,
269
362
  traceContext
270
363
  });
271
364
  const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
272
365
  return serializedSignature;
273
366
  } catch (error) {
274
- this.logger.error(ERROR_SIGN_TYPED_DATA, error);
275
- throw new Error(ERROR_SIGN_TYPED_DATA);
367
+ this.logOperationFailure(ERROR_SIGN_TYPED_DATA, error);
368
+ throw new Error(ERROR_SIGN_TYPED_DATA, {
369
+ cause: error
370
+ });
276
371
  }
277
372
  }
278
373
  deriveAccountAddress({ rawPublicKey }) {
@@ -287,7 +382,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
287
382
  publicKeyHex
288
383
  };
289
384
  }
290
- async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, traceContext }) {
385
+ async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, approvalQuorum, proposalId, traceContext }) {
291
386
  await this.verifyPassword({
292
387
  accountAddress,
293
388
  password,
@@ -300,6 +395,8 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
300
395
  signedSessionId,
301
396
  mfaToken,
302
397
  elevatedAccessToken,
398
+ approvalQuorum,
399
+ proposalId,
303
400
  traceContext
304
401
  });
305
402
  return derivedPrivateKey;
@@ -332,7 +429,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
332
429
  chainName,
333
430
  privateKey: formattedPrivateKey,
334
431
  thresholdSignatureScheme,
335
- onCeremonyComplete: (accountAddress, walletId, shareSetId)=>{
432
+ onCeremonyComplete: ({ accountAddress, walletId, shareSetId })=>{
336
433
  const checksumAddress = getAddress(accountAddress);
337
434
  this.initializeWalletMapEntry({
338
435
  accountAddress: checksumAddress,
@@ -354,7 +451,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
354
451
  throw new Error(ERROR_IMPORT_PRIVATE_KEY);
355
452
  }
356
453
  checkRawPublicKeyInstance(rawPublicKey);
357
- const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
454
+ const { accountAddress, publicKeyHex } = this.deriveAccountAddress({
358
455
  rawPublicKey: rawPublicKey
359
456
  });
360
457
  // Update client key shares in wallet map
@@ -384,22 +481,157 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
384
481
  const evmWallets = wallets.filter((wallet)=>wallet.chainName === 'EVM');
385
482
  return evmWallets;
386
483
  }
387
- constructor({ environmentId, authToken, backupServiceAuthToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode = AuthMode.HEADER, sdkVersion, forwardMPCClient, logger }, internalOptions){
388
- super({
389
- environmentId,
390
- authToken,
391
- backupServiceAuthToken,
392
- baseApiUrl,
393
- baseMPCRelayApiUrl,
394
- storageKey,
395
- debug,
396
- featureFlags,
397
- authMode,
398
- sdkVersion,
399
- forwardMPCClient,
400
- logger
401
- }, internalOptions), this.chainName = 'EVM';
484
+ constructor(...args){
485
+ super(...args), this.chainName = 'EVM';
402
486
  }
403
487
  }
404
488
 
405
- export { DynamicEvmWalletClient };
489
+ const decimal = (value)=>BigInt(value).toString(10);
490
+ const parseLimit = (value, name)=>{
491
+ if (!/^(0|[1-9]\d*)$/.test(value)) throw new Error(`Invalid ${name} signing limit`);
492
+ return BigInt(value);
493
+ };
494
+ const parseLimits = (limits)=>({
495
+ maxGas: parseLimit(limits.maxGas, 'maxGas'),
496
+ maxFeePerGas: parseLimit(limits.maxFeePerGas, 'maxFeePerGas'),
497
+ maxPriorityFeePerGas: parseLimit(limits.maxPriorityFeePerGas, 'maxPriorityFeePerGas'),
498
+ maxTotalFee: parseLimit(limits.maxTotalFee, 'maxTotalFee')
499
+ });
500
+ const prepareEvmTransactionSigningOperation = ({ transaction, accountAddress, refreshLimits, refreshableNonce = false })=>{
501
+ var _parsed_accessList;
502
+ const parsed = parseTransaction(transaction);
503
+ var _parsed_accessList_length;
504
+ if (parsed.type !== 'eip1559' || ((_parsed_accessList_length = (_parsed_accessList = parsed.accessList) == null ? void 0 : _parsed_accessList.length) != null ? _parsed_accessList_length : 0) !== 0) {
505
+ throw new Error('Signing intent supports only EIP-1559 transactions with an empty access list');
506
+ }
507
+ const { chainId, nonce, gas, maxFeePerGas } = parsed;
508
+ var _parsed_maxPriorityFeePerGas;
509
+ // viem drops zero-valued fee fields when parsing, so an absent tip is a valid zero tip.
510
+ const maxPriorityFeePerGas = (_parsed_maxPriorityFeePerGas = parsed.maxPriorityFeePerGas) != null ? _parsed_maxPriorityFeePerGas : 0n;
511
+ if (nonce === undefined || gas === undefined || maxFeePerGas === undefined || parsed.yParity !== undefined || parsed.r !== undefined || parsed.s !== undefined) {
512
+ throw new Error('Signing intent requires a complete unsigned EIP-1559 transaction');
513
+ }
514
+ if (gas === 0n || maxFeePerGas === 0n) {
515
+ throw new Error('Transaction gas and maximum fee must be positive');
516
+ }
517
+ const limits = refreshLimits != null ? refreshLimits : {
518
+ maxGas: decimal(gas),
519
+ maxFeePerGas: decimal(maxFeePerGas),
520
+ maxPriorityFeePerGas: decimal(maxPriorityFeePerGas),
521
+ maxTotalFee: decimal(gas * maxFeePerGas)
522
+ };
523
+ const parsedLimits = parseLimits(limits);
524
+ if (parsedLimits.maxGas < gas || parsedLimits.maxFeePerGas < maxFeePerGas || parsedLimits.maxPriorityFeePerGas < maxPriorityFeePerGas || parsedLimits.maxPriorityFeePerGas > parsedLimits.maxFeePerGas || gas * maxFeePerGas > parsedLimits.maxTotalFee) {
525
+ throw new Error('Transaction exceeds signing intent limits');
526
+ }
527
+ var _parsed_value, _parsed_data;
528
+ const prepared = {
529
+ operation: {
530
+ kind: 'transaction',
531
+ chainName: 'EVM',
532
+ chainId: decimal(chainId),
533
+ from: getAddress(accountAddress).toLowerCase(),
534
+ to: parsed.to ? getAddress(parsed.to).toLowerCase() : null,
535
+ value: decimal((_parsed_value = parsed.value) != null ? _parsed_value : 0n),
536
+ data: ((_parsed_data = parsed.data) != null ? _parsed_data : '0x').toLowerCase(),
537
+ nonce: decimal(nonce)
538
+ },
539
+ limits
540
+ };
541
+ if (refreshableNonce) prepared.lifetime = {
542
+ refreshable: 'nonce'
543
+ };
544
+ return prepared;
545
+ };
546
+ const safeNumber = (value, name)=>{
547
+ const parsed = parseLimit(value, name);
548
+ if (parsed > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error(`Invalid ${name} signing value`);
549
+ return Number(parsed);
550
+ };
551
+ /** The authorization is hashed from JS numbers, so a chain id or nonce must be an exact, in-range integer. */ const assertValidEip7702Auth = (eip7702Auth)=>{
552
+ if (!Number.isSafeInteger(eip7702Auth.chainId) || eip7702Auth.chainId <= 0) {
553
+ throw new Error('Invalid chainId signing value');
554
+ }
555
+ if (!Number.isSafeInteger(eip7702Auth.nonce) || eip7702Auth.nonce < 0) {
556
+ throw new Error('Invalid nonce signing value');
557
+ }
558
+ getAddress(eip7702Auth.address);
559
+ };
560
+ /**
561
+ * Builds the intent operation for an EIP-7702 authorization; `payload` is the hash the wallet signs.
562
+ * The authorization is carried unchanged so it can be compared with the sign request's context.
563
+ */ const prepareEip7702AuthSigningOperation = ({ eip7702Auth })=>{
564
+ assertValidEip7702Auth(eip7702Auth);
565
+ const { address, chainId, nonce } = eip7702Auth;
566
+ return {
567
+ operation: {
568
+ kind: 'eip7702Auth',
569
+ chainName: 'EVM',
570
+ eip7702Auth: {
571
+ address,
572
+ chainId,
573
+ nonce
574
+ },
575
+ payload: hashAuthorization({
576
+ chainId,
577
+ contractAddress: address,
578
+ nonce
579
+ }).slice(2)
580
+ }
581
+ };
582
+ };
583
+ /** Reads an approved operation's authorization, rejecting a zero, negative or unsafe chain id or nonce. */ const eip7702AuthorizationFromOperation = ({ operation })=>{
584
+ assertValidEip7702Auth(operation.eip7702Auth);
585
+ return operation.eip7702Auth;
586
+ };
587
+ /**
588
+ * Reconstructs an unsigned EIP-1559 transaction from an approved intent.
589
+ * Only gas and fee values may change, within the approved limits, plus the
590
+ * nonce when the intent signed a refreshable nonce. That nonce (`lifetimeValue`,
591
+ * decimal) is optional: without it, the nonce from the signed operation is used.
592
+ */ const resumeEvmTransactionSigningIntent = ({ intent, lifetimeValue })=>{
593
+ var _intent_lifetime;
594
+ if (intent.operation.kind !== 'transaction' || intent.operation.chainName !== 'EVM' || !intent.limits) {
595
+ throw new Error('Stored signing intent is not an EVM transaction');
596
+ }
597
+ const refreshableNonce = ((_intent_lifetime = intent.lifetime) == null ? void 0 : _intent_lifetime.refreshable) === 'nonce';
598
+ if (lifetimeValue !== undefined && !refreshableNonce) {
599
+ throw new Error('A nonce can be supplied only when the EVM transaction intent has a refreshable nonce');
600
+ }
601
+ const nonce = lifetimeValue != null ? lifetimeValue : intent.operation.nonce;
602
+ const { operation, limits } = intent;
603
+ const parsedLimits = parseLimits(limits);
604
+ if (parsedLimits.maxGas === 0n || parsedLimits.maxFeePerGas === 0n) {
605
+ throw new Error('Stored EVM transaction intent has unusable fee limits');
606
+ }
607
+ const gas = parsedLimits.maxGas;
608
+ // The signed total-fee ceiling can be tighter than the independent gas and
609
+ // fee ceilings, so derive the largest fee cap that satisfies all three.
610
+ const maxFeePerGas = parsedLimits.maxTotalFee / gas < parsedLimits.maxFeePerGas ? parsedLimits.maxTotalFee / gas : parsedLimits.maxFeePerGas;
611
+ if (maxFeePerGas === 0n) {
612
+ throw new Error('Stored EVM transaction intent has unusable fee limits');
613
+ }
614
+ const maxPriorityFeePerGas = parsedLimits.maxPriorityFeePerGas < maxFeePerGas ? parsedLimits.maxPriorityFeePerGas : maxFeePerGas;
615
+ const transaction = serializeTransaction({
616
+ chainId: safeNumber(operation.chainId, 'chainId'),
617
+ data: operation.data,
618
+ gas,
619
+ maxFeePerGas,
620
+ maxPriorityFeePerGas,
621
+ nonce: safeNumber(nonce, 'nonce'),
622
+ to: operation.to ? getAddress(operation.to) : undefined,
623
+ type: 'eip1559',
624
+ value: parseLimit(operation.value, 'value')
625
+ });
626
+ const reconstructed = prepareEvmTransactionSigningOperation({
627
+ accountAddress: intent.accountAddress,
628
+ refreshLimits: limits,
629
+ transaction
630
+ });
631
+ if (reconstructed.operation.chainId !== operation.chainId || reconstructed.operation.from !== operation.from || reconstructed.operation.to !== operation.to || reconstructed.operation.value !== operation.value || reconstructed.operation.data !== operation.data || reconstructed.operation.nonce !== nonce) {
632
+ throw new Error('Stored EVM transaction intent is malformed');
633
+ }
634
+ return transaction;
635
+ };
636
+
637
+ export { DynamicEvmWalletClient, eip7702AuthorizationFromOperation, prepareEip7702AuthSigningOperation, prepareEvmTransactionSigningOperation, resumeEvmTransactionSigningIntent, serializeEcdsaSignature };
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/evm",
3
- "version": "0.0.354",
3
+ "version": "0.1.0-request-signing",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@dynamic-labs-wallet/browser": "0.0.354",
8
- "@dynamic-labs-wallet/core": "0.0.354",
9
- "@dynamic-labs/sdk-api-core": "^0.0.984",
10
- "@faker-js/faker": "^9.5.0"
7
+ "@dynamic-labs-wallet/browser": "0.1.0-request-signing",
8
+ "@dynamic-labs-wallet/core": "0.1.0-request-signing",
9
+ "@dynamic-labs/sdk-api-core": "0.193.0"
11
10
  },
12
11
  "peerDependencies": {
13
- "viem": "^2.45.3"
12
+ "viem": "^2.56.9"
14
13
  },
15
14
  "publishConfig": {
16
15
  "access": "public"
@@ -1,72 +1,93 @@
1
- import { DynamicWalletClient, type DynamicWalletClientInternalOptions, type DynamicWalletClientProps, type EcdsaKeygenResult, type EcdsaPublicKey, type Ed25519KeygenResult, type ThresholdSignatureScheme, type TraceContext, type RequestWithElevatedAccessToken } from '@dynamic-labs-wallet/browser';
2
- import type { SignMessageContext } from '@dynamic-labs/sdk-api-core';
1
+ import { DynamicWalletClient, type EcdsaKeygenResult, type EcdsaPublicKey, type Ed25519KeygenResult, type ThresholdSignatureScheme, type TraceContext, type RequestWithElevatedAccessToken, type BaseSignParams, type SignAndBroadcastResponse, type ExportApprovalQuorumRequest } from '@dynamic-labs-wallet/browser';
3
2
  import { type Chain, type PublicClient, type SignableMessage, type TransactionSerializable, type TypedData } from 'viem';
4
3
  export declare class DynamicEvmWalletClient extends DynamicWalletClient {
5
4
  readonly chainName = "EVM";
6
- constructor({ environmentId, authToken, backupServiceAuthToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode, sdkVersion, forwardMPCClient, logger, }: DynamicWalletClientProps, internalOptions?: DynamicWalletClientInternalOptions);
7
5
  createViemPublicClient({ chain, rpcUrl }: {
8
6
  chain: Chain;
9
7
  rpcUrl?: string;
10
8
  }): PublicClient;
11
- createWalletAccount({ thresholdSignatureScheme, password, onError, signedSessionId, traceContext, }: {
9
+ /**
10
+ * Create an EVM wallet. When `businessAccountId` is passed the wallet is
11
+ * owned by that business account and redcoast creates the signer row mapping
12
+ * the new share set — same keygen + backup ceremony and endpoints either way.
13
+ */
14
+ createWalletAccount({ thresholdSignatureScheme, password, onError, signedSessionId, traceContext, businessAccountId, }: {
12
15
  thresholdSignatureScheme: ThresholdSignatureScheme;
13
16
  password?: string;
14
17
  onError?: (error: Error) => void;
15
18
  signedSessionId: string;
16
19
  traceContext?: TraceContext;
20
+ businessAccountId?: string;
17
21
  }): Promise<{
18
22
  accountAddress: string;
19
23
  publicKeyHex: string;
20
24
  rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
21
25
  }>;
22
- signMessage({ message, accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, context, onError, traceContext, }: {
26
+ signMessage({ message, accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, context, approvalQuorum, onError, traceContext, }: {
23
27
  message: string;
24
28
  accountAddress: string;
25
- password?: string;
26
- signedSessionId: string;
27
- mfaToken?: string;
28
- elevatedAccessToken?: string;
29
- context?: SignMessageContext;
30
- onError?: (error: Error) => void;
31
- traceContext?: TraceContext;
32
- }): Promise<`0x${string}`>;
29
+ } & BaseSignParams): Promise<`0x${string}`>;
30
+ prepareSignMessage({ message }: {
31
+ message: string;
32
+ }): string;
33
33
  verifyMessageSignature({ accountAddress, message, signature, }: {
34
34
  accountAddress: string;
35
35
  message: SignableMessage;
36
36
  signature: any;
37
37
  }): Promise<boolean>;
38
- signTransaction({ senderAddress, transaction, password, signedSessionId, mfaToken, elevatedAccessToken, context, onError, traceContext, }: {
38
+ prepareSignTransaction({ transaction }: {
39
+ transaction: TransactionSerializable;
40
+ }): string;
41
+ prepareSignTypedData({ typedData }: {
42
+ typedData: TypedData;
43
+ }): string;
44
+ signTransaction({ senderAddress, transaction, password, signedSessionId, mfaToken, elevatedAccessToken, context, approvalQuorum, onError, traceContext, }: {
39
45
  senderAddress: string;
40
46
  transaction: TransactionSerializable;
41
- password?: string;
42
- signedSessionId: string;
43
- mfaToken?: string;
44
- elevatedAccessToken?: string;
45
- context?: SignMessageContext;
46
- onError?: (error: Error) => void;
47
- traceContext?: TraceContext;
48
- }): Promise<string>;
49
- signTypedData({ accountAddress, typedData, password, signedSessionId, mfaToken, elevatedAccessToken, onError, traceContext, }: {
47
+ } & BaseSignParams): Promise<string>;
48
+ /**
49
+ * Signs the transaction for Dynamic to broadcast.
50
+ *
51
+ * @param params.senderAddress - The wallet's address.
52
+ * @param params.transaction - The transaction, with its fee: `gasPrice`, or `maxFeePerGas` with `maxPriorityFeePerGas`.
53
+ * @param params.requestedCertainty - How sure to be before calling it confirmed: `fast`, `safe` or `final`, or `chain:` plus a chain-specific value. Defaults to `safe`.
54
+ * @param params.externalReference - Your own label, returned on every event. Not unique.
55
+ * @param params.idempotencyKey - Makes a retry safe: the same key replays the stored answer instead of sending twice. A new one is made when omitted.
56
+ * @param params.password - The wallet's backup password, if it has one.
57
+ * @param params.signedSessionId - The signed-in session, used to unlock the wallet's key share.
58
+ * @param params.mfaToken - Proof of the user's multi-factor check, when the wallet needs one.
59
+ * @param params.elevatedAccessToken - Proof of a recent re-login, when the wallet needs one.
60
+ * @param params.approvalQuorum - Approvers' consent for a governed wallet, sent on the retry after `intent_required`.
61
+ * @param params.onError - Called with the failure's message, never the raw error.
62
+ * @param params.traceContext - Ties this call's logs to the server's, across retries. Created when omitted.
63
+ * @returns The transaction record.
64
+ */
65
+ signAndBroadcastTransaction({ senderAddress, transaction, password, signedSessionId, mfaToken, elevatedAccessToken, approvalQuorum, requestedCertainty, externalReference, idempotencyKey, onError, traceContext, }: {
66
+ senderAddress: string;
67
+ transaction: TransactionSerializable;
68
+ requestedCertainty?: string;
69
+ externalReference?: string;
70
+ idempotencyKey?: string;
71
+ } & Pick<BaseSignParams, 'password' | 'signedSessionId' | 'mfaToken' | 'elevatedAccessToken' | 'approvalQuorum' | 'onError' | 'traceContext'>): Promise<SignAndBroadcastResponse>;
72
+ signTypedData({ accountAddress, typedData, password, signedSessionId, mfaToken, elevatedAccessToken, approvalQuorum, onError, traceContext, }: {
50
73
  accountAddress: string;
51
74
  typedData: TypedData;
52
- password?: string;
53
- signedSessionId: string;
54
- mfaToken?: string;
55
- elevatedAccessToken?: string;
56
- onError?: (error: Error) => void;
57
- traceContext?: TraceContext;
58
- }): Promise<`0x${string}`>;
75
+ } & BaseSignParams): Promise<`0x${string}`>;
59
76
  deriveAccountAddress({ rawPublicKey }: {
60
77
  rawPublicKey: EcdsaPublicKey;
61
78
  }): {
62
79
  accountAddress: `0x${string}`;
63
80
  publicKeyHex: string;
64
81
  };
65
- exportPrivateKey({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, traceContext, }: RequestWithElevatedAccessToken<{
82
+ exportPrivateKey({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, approvalQuorum, proposalId, traceContext, }: RequestWithElevatedAccessToken<{
66
83
  accountAddress: string;
67
84
  password?: string;
68
85
  signedSessionId: string;
69
86
  mfaToken?: string;
87
+ /** The initiator's signed export Intent, from `prepareExportIntent`. */
88
+ approvalQuorum?: ExportApprovalQuorumRequest;
89
+ /** The approved export proposal being redeemed, from the consent error the export call raised. */
90
+ proposalId?: string;
70
91
  traceContext?: TraceContext;
71
92
  }>): Promise<string | undefined>;
72
93
  offlineExportPrivateKey({ keyShares, derivationPath, }: {
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAWnB,KAAK,kCAAkC,EACvC,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAEnB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,8BAA8B,EACpC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAA2B,MAAM,4BAA4B,CAAC;AAC9F,OAAO,EAKL,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AAMd,qB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B,EAClB,cAAc,GACf,EAAE;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,wBAAwB,EAAE,wBAAwB,CAAC;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;QACjC,eAAe,EAAE,MAAM,CAAC;QACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,4DAA4D;QAC5D,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,cAAc,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;KAChE,CAAC;IA4EI,aAAa;CAKpB"}
@@ -1,4 +1,4 @@
1
- import type { SignMessageEvmTransaction } from '@dynamic-labs/sdk-api-core';
1
+ import type { SignMessageEvmTransaction } from '@dynamic-labs-wallet/core';
2
2
  import type { TransactionSerializable } from 'viem';
3
3
  export declare const checkRawPublicKeyInstance: (rawPublicKey: any) => void;
4
4
  export declare const mapTransactionToEvmTransaction: (transaction: TransactionSerializable) => SignMessageEvmTransaction;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/client/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,MAAM,CAAC;AAEpD,eAAO,MAAM,yBAAyB,iBAAkB,GAAG,SAI1D,CAAC;AAEF,eAAO,MAAM,8BAA8B,gBAAiB,uBAAuB,KAAG,yBAYpF,CAAC"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/client/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAG3E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,MAAM,CAAC;AAEpD,eAAO,MAAM,yBAAyB,iBAAkB,GAAG,SAI1D,CAAC;AAEF,eAAO,MAAM,8BAA8B,gBAAiB,uBAAuB,KAAG,yBAYpF,CAAC"}
package/src/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './client/index.js';
2
+ export { eip7702AuthorizationFromOperation, prepareEip7702AuthSigningOperation, prepareEvmTransactionSigningOperation, resumeEvmTransactionSigningIntent, } from './signingIntent.js';
3
+ export { serializeEcdsaSignature } from './utils.js';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EACL,iCAAiC,EACjC,kCAAkC,EAClC,qCAAqC,EACrC,iCAAiC,GAClC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { Eip7702AuthOperation, EvmSigningIntentLimits, PreparedEvmTransactionSigningIntent, SigningIntent } from '@dynamic-labs-wallet/core';
2
+ export declare const prepareEvmTransactionSigningOperation: ({ transaction, accountAddress, refreshLimits, refreshableNonce, }: {
3
+ transaction: string;
4
+ accountAddress: string;
5
+ refreshLimits?: EvmSigningIntentLimits;
6
+ /** Explicit opt-in to sign a refreshable nonce. Absent by default, which keeps the nonce pinned. */
7
+ refreshableNonce?: boolean;
8
+ }) => PreparedEvmTransactionSigningIntent;
9
+ type Eip7702Auth = Eip7702AuthOperation['eip7702Auth'];
10
+ /**
11
+ * Builds the intent operation for an EIP-7702 authorization; `payload` is the hash the wallet signs.
12
+ * The authorization is carried unchanged so it can be compared with the sign request's context.
13
+ */
14
+ export declare const prepareEip7702AuthSigningOperation: ({ eip7702Auth, }: {
15
+ eip7702Auth: Eip7702Auth;
16
+ }) => {
17
+ operation: Eip7702AuthOperation;
18
+ };
19
+ /** Reads an approved operation's authorization, rejecting a zero, negative or unsafe chain id or nonce. */
20
+ export declare const eip7702AuthorizationFromOperation: ({ operation }: {
21
+ operation: Eip7702AuthOperation;
22
+ }) => Eip7702Auth;
23
+ /**
24
+ * Reconstructs an unsigned EIP-1559 transaction from an approved intent.
25
+ * Only gas and fee values may change, within the approved limits, plus the
26
+ * nonce when the intent signed a refreshable nonce. That nonce (`lifetimeValue`,
27
+ * decimal) is optional: without it, the nonce from the signed operation is used.
28
+ */
29
+ export declare const resumeEvmTransactionSigningIntent: ({ intent, lifetimeValue, }: {
30
+ intent: SigningIntent;
31
+ lifetimeValue?: string;
32
+ }) => string;
33
+ export {};
34
+ //# sourceMappingURL=signingIntent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signingIntent.d.ts","sourceRoot":"","sources":["../../packages/src/signingIntent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,mCAAmC,EACnC,aAAa,EACd,MAAM,2BAA2B,CAAC;AAkBnC,eAAO,MAAM,qCAAqC,sEAK/C;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACvC,oGAAoG;IACpG,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,KAAG,mCAsDH,CAAC;AAQF,KAAK,WAAW,GAAG,oBAAoB,CAAC,aAAa,CAAC,CAAC;AAavD;;;GAGG;AACH,eAAO,MAAM,kCAAkC,qBAE5C;IACD,WAAW,EAAE,WAAW,CAAC;CAC1B,KAAG;IAAE,SAAS,EAAE,oBAAoB,CAAA;CAYpC,CAAC;AAEF,2GAA2G;AAC3G,eAAO,MAAM,iCAAiC,kBAAmB;IAAE,SAAS,EAAE,oBAAoB,CAAA;CAAE,KAAG,WAItG,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iCAAiC,+BAG3C;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,KAAG,MAwDH,CAAC"}
package/src/utils.d.ts CHANGED
@@ -7,5 +7,6 @@ export declare const formatEVMMessage: (message_: string | {
7
7
  export declare const formatTypedData: (typedData: TypedData | {
8
8
  [key: string]: unknown;
9
9
  }) => string;
10
+ export declare const serializeEcdsaSignature: (signature: EcdsaSignature) => `0x${string}`;
10
11
  export declare const serializeECDSASignature: (signature: EcdsaSignature, logger: ILogger) => `0x${string}`;
11
12
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../packages/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAA2B,SAAS,EAAE,MAAM,MAAM,CAAC;AAI/D,eAAO,MAAM,gBAAgB,aAAc,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,UAAU,OAAO,kBAahG,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,SAAS,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,WAEhF,CAAC;AAEF,eAAO,MAAM,uBAAuB,cAAe,cAAc,UAAU,OAAO,kBAWjF,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../packages/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAA2B,SAAS,EAAE,MAAM,MAAM,CAAC;AAI/D,eAAO,MAAM,gBAAgB,aAAc,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,UAAU,OAAO,kBAahG,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,SAAS,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,WA6BhF,CAAC;AAEF,eAAO,MAAM,uBAAuB,cAAe,cAAc,kBAK7D,CAAC;AAEL,eAAO,MAAM,uBAAuB,cAAe,cAAc,UAAU,OAAO,kBAOjF,CAAC"}