@dynamic-labs-wallet/evm 0.0.353 → 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)=>{
128
+ onCeremonyComplete: ({ accountAddress, walletId, shareSetId })=>{
97
129
  const checksumAddress = viem.getAddress(accountAddress);
98
130
  const chainConfig = browser.getMPCChainConfig(this.chainName);
99
131
  this.initializeWalletMapEntry({
@@ -104,7 +136,8 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
104
136
  derivationPath: JSON.stringify(Object.fromEntries(chainConfig.derivationPath.map((value, index)=>[
105
137
  index,
106
138
  value
107
- ])))
139
+ ]))),
140
+ shareSetId
108
141
  });
109
142
  // Resolve the promise when ceremony is complete
110
143
  ceremonyCeremonyCompleteResolver(undefined);
@@ -118,7 +151,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
118
151
  throw new Error(browser.ERROR_KEYGEN_FAILED);
119
152
  }
120
153
  checkRawPublicKeyInstance(rawPublicKey);
121
- const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
154
+ const { accountAddress, publicKeyHex } = this.deriveAccountAddress({
122
155
  rawPublicKey: rawPublicKey
123
156
  });
124
157
  // Update client key shares in wallet map
@@ -130,7 +163,8 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
130
163
  accountAddress,
131
164
  clientKeyShares,
132
165
  password,
133
- signedSessionId
166
+ signedSessionId,
167
+ businessAccountId
134
168
  });
135
169
  return {
136
170
  accountAddress,
@@ -138,15 +172,17 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
138
172
  publicKeyHex
139
173
  };
140
174
  } catch (error) {
141
- // Re-throw password mismatch errors without wrapping
142
- 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)) {
143
177
  throw error;
144
178
  }
145
179
  this.logger.error(browser.ERROR_CREATE_WALLET_ACCOUNT, error);
146
- throw new Error(browser.ERROR_CREATE_WALLET_ACCOUNT);
180
+ throw new Error(browser.ERROR_CREATE_WALLET_ACCOUNT, {
181
+ cause: error
182
+ });
147
183
  }
148
184
  }
149
- 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 }) {
150
186
  await this.verifyPassword({
151
187
  accountAddress,
152
188
  password,
@@ -157,7 +193,9 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
157
193
  throw new Error(browser.ERROR_ACCOUNT_ADDRESS_REQUIRED);
158
194
  }
159
195
  // Format the message for EVM signing
160
- const formattedMessage = formatEVMMessage(message, this.logger);
196
+ const formattedMessage = this.prepareSignMessage({
197
+ message
198
+ });
161
199
  const resolvedContext = context != null ? context : {
162
200
  evmMessage: message
163
201
  };
@@ -171,6 +209,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
171
209
  mfaToken,
172
210
  elevatedAccessToken,
173
211
  context: resolvedContext,
212
+ approvalQuorum,
174
213
  onError,
175
214
  traceContext
176
215
  });
@@ -178,10 +217,15 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
178
217
  const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
179
218
  return serializedSignature;
180
219
  } catch (error) {
181
- this.logger.error(browser.ERROR_SIGN_MESSAGE, error);
182
- 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
+ });
183
224
  }
184
225
  }
226
+ prepareSignMessage({ message }) {
227
+ return formatEVMMessage(message, this.logger);
228
+ }
185
229
  async verifyMessageSignature({ accountAddress, message, signature }) {
186
230
  try {
187
231
  // Verify the signature using the public client
@@ -199,13 +243,21 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
199
243
  throw new Error(browser.ERROR_VERIFY_MESSAGE_SIGNATURE);
200
244
  }
201
245
  }
202
- 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 }) {
203
253
  await this.verifyPassword({
204
254
  accountAddress: senderAddress,
205
255
  password,
206
256
  signedSessionId
207
257
  });
208
- const serializedTx = viem.serializeTransaction(transaction);
258
+ const serializedTx = this.prepareSignTransaction({
259
+ transaction
260
+ });
209
261
  const serializedTxBytes = Uint8Array.from(Buffer.from(serializedTx.slice(2), 'hex'));
210
262
  if (!(serializedTxBytes instanceof Uint8Array)) {
211
263
  throw new Error('Invalid serializedTxBytes');
@@ -222,6 +274,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
222
274
  context: _extends({}, context, {
223
275
  evmTransaction: mapTransactionToEvmTransaction(transaction)
224
276
  }),
277
+ approvalQuorum,
225
278
  onError,
226
279
  traceContext
227
280
  });
@@ -243,7 +296,45 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
243
296
  throw error;
244
297
  }
245
298
  }
246
- 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 }) {
247
338
  await this.verifyPassword({
248
339
  accountAddress,
249
340
  password,
@@ -253,7 +344,9 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
253
344
  if (!accountAddress) {
254
345
  throw new Error(browser.ERROR_ACCOUNT_ADDRESS_REQUIRED);
255
346
  }
256
- const formattedTypedData = formatTypedData(typedData);
347
+ const formattedTypedData = this.prepareSignTypedData({
348
+ typedData
349
+ });
257
350
  const signatureEcdsa = await this.sign({
258
351
  message: formattedTypedData,
259
352
  accountAddress: accountAddress,
@@ -266,14 +359,17 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
266
359
  context: {
267
360
  evmTypedData: typedData
268
361
  },
362
+ approvalQuorum,
269
363
  onError,
270
364
  traceContext
271
365
  });
272
366
  const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
273
367
  return serializedSignature;
274
368
  } catch (error) {
275
- this.logger.error(browser.ERROR_SIGN_TYPED_DATA, error);
276
- 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
+ });
277
373
  }
278
374
  }
279
375
  deriveAccountAddress({ rawPublicKey }) {
@@ -288,7 +384,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
288
384
  publicKeyHex
289
385
  };
290
386
  }
291
- async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, traceContext }) {
387
+ async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, approvalQuorum, proposalId, traceContext }) {
292
388
  await this.verifyPassword({
293
389
  accountAddress,
294
390
  password,
@@ -301,6 +397,8 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
301
397
  signedSessionId,
302
398
  mfaToken,
303
399
  elevatedAccessToken,
400
+ approvalQuorum,
401
+ proposalId,
304
402
  traceContext
305
403
  });
306
404
  return derivedPrivateKey;
@@ -333,13 +431,14 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
333
431
  chainName,
334
432
  privateKey: formattedPrivateKey,
335
433
  thresholdSignatureScheme,
336
- onCeremonyComplete: (accountAddress, walletId)=>{
434
+ onCeremonyComplete: ({ accountAddress, walletId, shareSetId })=>{
337
435
  const checksumAddress = viem.getAddress(accountAddress);
338
436
  this.initializeWalletMapEntry({
339
437
  accountAddress: checksumAddress,
340
438
  walletId,
341
439
  chainName: this.chainName,
342
- thresholdSignatureScheme
440
+ thresholdSignatureScheme,
441
+ shareSetId
343
442
  });
344
443
  ceremonyCeremonyCompleteResolver(undefined);
345
444
  },
@@ -354,7 +453,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
354
453
  throw new Error(browser.ERROR_IMPORT_PRIVATE_KEY);
355
454
  }
356
455
  checkRawPublicKeyInstance(rawPublicKey);
357
- const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
456
+ const { accountAddress, publicKeyHex } = this.deriveAccountAddress({
358
457
  rawPublicKey: rawPublicKey
359
458
  });
360
459
  // Update client key shares in wallet map
@@ -384,22 +483,162 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
384
483
  const evmWallets = wallets.filter((wallet)=>wallet.chainName === 'EVM');
385
484
  return evmWallets;
386
485
  }
387
- constructor({ environmentId, authToken, backupServiceAuthToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode = browser.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';
486
+ constructor(...args){
487
+ super(...args), this.chainName = 'EVM';
402
488
  }
403
489
  }
404
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
+
405
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)=>{
126
+ onCeremonyComplete: ({ accountAddress, walletId, shareSetId })=>{
95
127
  const checksumAddress = getAddress(accountAddress);
96
128
  const chainConfig = getMPCChainConfig(this.chainName);
97
129
  this.initializeWalletMapEntry({
@@ -102,7 +134,8 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
102
134
  derivationPath: JSON.stringify(Object.fromEntries(chainConfig.derivationPath.map((value, index)=>[
103
135
  index,
104
136
  value
105
- ])))
137
+ ]))),
138
+ shareSetId
106
139
  });
107
140
  // Resolve the promise when ceremony is complete
108
141
  ceremonyCeremonyCompleteResolver(undefined);
@@ -116,7 +149,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
116
149
  throw new Error(ERROR_KEYGEN_FAILED);
117
150
  }
118
151
  checkRawPublicKeyInstance(rawPublicKey);
119
- const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
152
+ const { accountAddress, publicKeyHex } = this.deriveAccountAddress({
120
153
  rawPublicKey: rawPublicKey
121
154
  });
122
155
  // Update client key shares in wallet map
@@ -128,7 +161,8 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
128
161
  accountAddress,
129
162
  clientKeyShares,
130
163
  password,
131
- signedSessionId
164
+ signedSessionId,
165
+ businessAccountId
132
166
  });
133
167
  return {
134
168
  accountAddress,
@@ -136,15 +170,17 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
136
170
  publicKeyHex
137
171
  };
138
172
  } catch (error) {
139
- // Re-throw password mismatch errors without wrapping
140
- 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)) {
141
175
  throw error;
142
176
  }
143
177
  this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
144
- throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
178
+ throw new Error(ERROR_CREATE_WALLET_ACCOUNT, {
179
+ cause: error
180
+ });
145
181
  }
146
182
  }
147
- 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 }) {
148
184
  await this.verifyPassword({
149
185
  accountAddress,
150
186
  password,
@@ -155,7 +191,9 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
155
191
  throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
156
192
  }
157
193
  // Format the message for EVM signing
158
- const formattedMessage = formatEVMMessage(message, this.logger);
194
+ const formattedMessage = this.prepareSignMessage({
195
+ message
196
+ });
159
197
  const resolvedContext = context != null ? context : {
160
198
  evmMessage: message
161
199
  };
@@ -169,6 +207,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
169
207
  mfaToken,
170
208
  elevatedAccessToken,
171
209
  context: resolvedContext,
210
+ approvalQuorum,
172
211
  onError,
173
212
  traceContext
174
213
  });
@@ -176,10 +215,15 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
176
215
  const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
177
216
  return serializedSignature;
178
217
  } catch (error) {
179
- this.logger.error(ERROR_SIGN_MESSAGE, error);
180
- throw new Error(ERROR_SIGN_MESSAGE);
218
+ this.logOperationFailure(ERROR_SIGN_MESSAGE, error);
219
+ throw new Error(ERROR_SIGN_MESSAGE, {
220
+ cause: error
221
+ });
181
222
  }
182
223
  }
224
+ prepareSignMessage({ message }) {
225
+ return formatEVMMessage(message, this.logger);
226
+ }
183
227
  async verifyMessageSignature({ accountAddress, message, signature }) {
184
228
  try {
185
229
  // Verify the signature using the public client
@@ -197,13 +241,21 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
197
241
  throw new Error(ERROR_VERIFY_MESSAGE_SIGNATURE);
198
242
  }
199
243
  }
200
- 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 }) {
201
251
  await this.verifyPassword({
202
252
  accountAddress: senderAddress,
203
253
  password,
204
254
  signedSessionId
205
255
  });
206
- const serializedTx = serializeTransaction(transaction);
256
+ const serializedTx = this.prepareSignTransaction({
257
+ transaction
258
+ });
207
259
  const serializedTxBytes = Uint8Array.from(Buffer.from(serializedTx.slice(2), 'hex'));
208
260
  if (!(serializedTxBytes instanceof Uint8Array)) {
209
261
  throw new Error('Invalid serializedTxBytes');
@@ -220,6 +272,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
220
272
  context: _extends({}, context, {
221
273
  evmTransaction: mapTransactionToEvmTransaction(transaction)
222
274
  }),
275
+ approvalQuorum,
223
276
  onError,
224
277
  traceContext
225
278
  });
@@ -241,7 +294,45 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
241
294
  throw error;
242
295
  }
243
296
  }
244
- 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 }) {
245
336
  await this.verifyPassword({
246
337
  accountAddress,
247
338
  password,
@@ -251,7 +342,9 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
251
342
  if (!accountAddress) {
252
343
  throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
253
344
  }
254
- const formattedTypedData = formatTypedData(typedData);
345
+ const formattedTypedData = this.prepareSignTypedData({
346
+ typedData
347
+ });
255
348
  const signatureEcdsa = await this.sign({
256
349
  message: formattedTypedData,
257
350
  accountAddress: accountAddress,
@@ -264,14 +357,17 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
264
357
  context: {
265
358
  evmTypedData: typedData
266
359
  },
360
+ approvalQuorum,
267
361
  onError,
268
362
  traceContext
269
363
  });
270
364
  const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
271
365
  return serializedSignature;
272
366
  } catch (error) {
273
- this.logger.error(ERROR_SIGN_TYPED_DATA, error);
274
- 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
+ });
275
371
  }
276
372
  }
277
373
  deriveAccountAddress({ rawPublicKey }) {
@@ -286,7 +382,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
286
382
  publicKeyHex
287
383
  };
288
384
  }
289
- async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, traceContext }) {
385
+ async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken, elevatedAccessToken, approvalQuorum, proposalId, traceContext }) {
290
386
  await this.verifyPassword({
291
387
  accountAddress,
292
388
  password,
@@ -299,6 +395,8 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
299
395
  signedSessionId,
300
396
  mfaToken,
301
397
  elevatedAccessToken,
398
+ approvalQuorum,
399
+ proposalId,
302
400
  traceContext
303
401
  });
304
402
  return derivedPrivateKey;
@@ -331,13 +429,14 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
331
429
  chainName,
332
430
  privateKey: formattedPrivateKey,
333
431
  thresholdSignatureScheme,
334
- onCeremonyComplete: (accountAddress, walletId)=>{
432
+ onCeremonyComplete: ({ accountAddress, walletId, shareSetId })=>{
335
433
  const checksumAddress = getAddress(accountAddress);
336
434
  this.initializeWalletMapEntry({
337
435
  accountAddress: checksumAddress,
338
436
  walletId,
339
437
  chainName: this.chainName,
340
- thresholdSignatureScheme
438
+ thresholdSignatureScheme,
439
+ shareSetId
341
440
  });
342
441
  ceremonyCeremonyCompleteResolver(undefined);
343
442
  },
@@ -352,7 +451,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
352
451
  throw new Error(ERROR_IMPORT_PRIVATE_KEY);
353
452
  }
354
453
  checkRawPublicKeyInstance(rawPublicKey);
355
- const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
454
+ const { accountAddress, publicKeyHex } = this.deriveAccountAddress({
356
455
  rawPublicKey: rawPublicKey
357
456
  });
358
457
  // Update client key shares in wallet map
@@ -382,22 +481,157 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
382
481
  const evmWallets = wallets.filter((wallet)=>wallet.chainName === 'EVM');
383
482
  return evmWallets;
384
483
  }
385
- constructor({ environmentId, authToken, backupServiceAuthToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode = AuthMode.HEADER, sdkVersion, forwardMPCClient, logger }, internalOptions){
386
- super({
387
- environmentId,
388
- authToken,
389
- backupServiceAuthToken,
390
- baseApiUrl,
391
- baseMPCRelayApiUrl,
392
- storageKey,
393
- debug,
394
- featureFlags,
395
- authMode,
396
- sdkVersion,
397
- forwardMPCClient,
398
- logger
399
- }, internalOptions), this.chainName = 'EVM';
484
+ constructor(...args){
485
+ super(...args), this.chainName = 'EVM';
400
486
  }
401
487
  }
402
488
 
403
- 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.353",
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.353",
8
- "@dynamic-labs-wallet/core": "0.0.353",
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,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,QAAQ,CAAC,SAAS,SAAS;gBAGzB,EACE,aAAa,EACb,SAAS,EACT,sBAAsB,EACtB,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,KAAK,EACL,YAAY,EACZ,QAA0B,EAC1B,UAAU,EACV,gBAAgB,EAChB,MAAM,GACP,EAAE,wBAAwB,EAC3B,eAAe,CAAC,EAAE,kCAAkC;IAqBtD,sBAAsB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,YAAY;IAOpF,mBAAmB,CAAC,EACxB,wBAAwB,EACxB,QAAoB,EACpB,OAAO,EACP,eAAe,EACf,YAAY,GACb,EAAE;QACD,wBAAwB,EAAE,wBAAwB,CA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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"}