@dynamic-labs-wallet/browser-wallet-client 1.1.68 → 1.1.70

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
@@ -2398,8 +2398,10 @@ const limitKeys = [
2398
2398
  'maxTotalFee'
2399
2399
  ];
2400
2400
  const isHex = (value)=>typeof value === 'string' && /^0x(?:[0-9a-f]{2})*$/.test(value);
2401
+ const isTransactionIntent = (intent)=>intent.operation.kind === 'transaction';
2401
2402
  const isSvmTransactionIntent = (intent)=>intent.operation.kind === 'transaction' && intent.operation.chainName === 'SVM';
2402
2403
  const isEvmTransactionIntent = (intent)=>intent.operation.kind === 'transaction' && intent.operation.chainName === 'EVM';
2404
+ const isTronTransactionIntent = (intent)=>intent.operation.kind === 'transaction' && intent.operation.chainName === 'TRON';
2403
2405
  const assertMatches = (matches, message)=>{
2404
2406
  if (!matches) throw new Error(message);
2405
2407
  };
@@ -2427,6 +2429,14 @@ const assertSvmTransactionMatchesRequest = (intent, request)=>{
2427
2429
  const isBase58 = (value)=>/^[1-9A-HJ-NP-Za-km-z]+$/.test(value);
2428
2430
  assertMatches(request.chainName === 'SVM' && Boolean(request.chainId) && ((_request_chainId = request.chainId) == null ? void 0 : _request_chainId.trim()) === request.chainId && operation.chainId === request.chainId && request.refreshLimits === undefined && !request.refreshableNonce && intent.limits === undefined && hasLifetime(intent.lifetime, 'blockhash') && (operation.messageVersion === 'legacy' || operation.messageVersion === 'v0') && operation.staticAccountKeys.length > 0 && operation.staticAccountKeys.every(isBase58) && operation.feePayer === request.accountAddress && operation.feePayer === operation.staticAccountKeys[0] && hasValidSvmHeader(intent) && hasValidSvmInstructions(intent), 'Prepared SVM transaction signing intent is malformed');
2429
2431
  };
2432
+ // The intent describes the network in decimal; a request may name it in hexadecimal.
2433
+ const toDecimalChainId = (chainId)=>chainId && /^0x[\da-f]+$/i.test(chainId) ? BigInt(chainId).toString() : chainId;
2434
+ const assertTronTransactionMatchesRequest = (intent, request)=>{
2435
+ const { operation } = intent;
2436
+ // Wallet-service parses the transaction it signs and rejects any mismatch with
2437
+ // the approved operation, so the contract fields are not re-derived here.
2438
+ assertMatches(request.chainName === 'TRON' && Boolean(request.chainId) && operation.chainId === toDecimalChainId(request.chainId) && request.refreshLimits === undefined && !request.refreshableNonce && intent.limits === undefined && hasLifetime(intent.lifetime, 'expiration') && operation.from === request.accountAddress, 'Prepared TRON transaction signing intent is malformed');
2439
+ };
2430
2440
  const assertEvmTransactionMatchesRequest = (intent, request)=>{
2431
2441
  if (request.chainName !== 'EVM') throw new Error('Unsupported transaction signing intent');
2432
2442
  const { operation, limits } = intent;
@@ -2441,28 +2451,24 @@ const assertEvmTransactionMatchesRequest = (intent, request)=>{
2441
2451
  // Wallet-service parses the transaction it signs and rejects any mismatch with
2442
2452
  // the approved operation, so the transaction fields are not re-derived here.
2443
2453
  };
2444
- const assertPreparedSigningIntentMatchesRequest = ({ intent, request, preparedPayload })=>{
2445
- assertMatches(hasMatchingMetadata(intent, request), 'Prepared signing intent does not match request');
2446
- if (intent.operation.kind === 'transaction') {
2447
- if (request.kind !== 'transaction') {
2448
- throw new Error('Unsupported transaction signing intent');
2449
- }
2450
- if (isSvmTransactionIntent(intent)) {
2451
- assertSvmTransactionMatchesRequest(intent, request);
2452
- return;
2453
- }
2454
- if (!isEvmTransactionIntent(intent)) {
2455
- throw new Error('Unsupported transaction signing intent');
2456
- }
2457
- assertEvmTransactionMatchesRequest(intent, request);
2458
- return;
2454
+ const assertTransactionIntentMatchesRequest = (intent, request)=>{
2455
+ if (request.kind !== 'transaction') {
2456
+ throw new Error('Unsupported transaction signing intent');
2459
2457
  }
2458
+ if (isSvmTransactionIntent(intent)) return assertSvmTransactionMatchesRequest(intent, request);
2459
+ if (isTronTransactionIntent(intent)) return assertTronTransactionMatchesRequest(intent, request);
2460
+ if (!isEvmTransactionIntent(intent)) {
2461
+ throw new Error('Unsupported transaction signing intent');
2462
+ }
2463
+ return assertEvmTransactionMatchesRequest(intent, request);
2464
+ };
2465
+ const assertExactOperationMatchesRequest = ({ intent, request, preparedPayload })=>{
2460
2466
  const { operation } = intent;
2461
2467
  assertMatches(preparedPayload !== undefined && operation.payload === preparedPayload, 'Prepared signing intent payload does not match request');
2462
2468
  assertMatches(intent.limits === undefined, 'Exact signing intent cannot include refresh limits');
2463
2469
  assertMatches(hasLifetime(intent.lifetime, undefined), 'Exact signing intent cannot include a lifetime');
2464
2470
  if (operation.kind === 'message') {
2465
- assertMatches(request.kind === 'message' && request.chainName !== 'TRON' && operation.message === request.message, 'Prepared signing intent message does not match request');
2471
+ assertMatches(request.kind === 'message' && operation.message === request.message, 'Prepared signing intent message does not match request');
2466
2472
  return;
2467
2473
  }
2468
2474
  if (operation.kind === 'typedData') {
@@ -2476,6 +2482,18 @@ const assertPreparedSigningIntentMatchesRequest = ({ intent, request, preparedPa
2476
2482
  const rawSign = operation.rawSign;
2477
2483
  assertMatches(request.kind === 'raw' && (rawSign == null ? void 0 : rawSign.payload) === request.rawSign.payload && rawSign.hashFunction === request.rawSign.hashFunction && rawSign.prefix === request.rawSign.prefix, 'Prepared raw signing intent does not match request');
2478
2484
  };
2485
+ const assertPreparedSigningIntentMatchesRequest = ({ intent, request, preparedPayload })=>{
2486
+ assertMatches(hasMatchingMetadata(intent, request), 'Prepared signing intent does not match request');
2487
+ if (isTransactionIntent(intent)) {
2488
+ assertTransactionIntentMatchesRequest(intent, request);
2489
+ return;
2490
+ }
2491
+ assertExactOperationMatchesRequest({
2492
+ intent,
2493
+ request,
2494
+ preparedPayload
2495
+ });
2496
+ };
2479
2497
 
2480
2498
  Object.defineProperty(exports, "AuthMode", {
2481
2499
  enumerable: true,
package/index.esm.js CHANGED
@@ -2397,8 +2397,10 @@ const limitKeys = [
2397
2397
  'maxTotalFee'
2398
2398
  ];
2399
2399
  const isHex = (value)=>typeof value === 'string' && /^0x(?:[0-9a-f]{2})*$/.test(value);
2400
+ const isTransactionIntent = (intent)=>intent.operation.kind === 'transaction';
2400
2401
  const isSvmTransactionIntent = (intent)=>intent.operation.kind === 'transaction' && intent.operation.chainName === 'SVM';
2401
2402
  const isEvmTransactionIntent = (intent)=>intent.operation.kind === 'transaction' && intent.operation.chainName === 'EVM';
2403
+ const isTronTransactionIntent = (intent)=>intent.operation.kind === 'transaction' && intent.operation.chainName === 'TRON';
2402
2404
  const assertMatches = (matches, message)=>{
2403
2405
  if (!matches) throw new Error(message);
2404
2406
  };
@@ -2426,6 +2428,14 @@ const assertSvmTransactionMatchesRequest = (intent, request)=>{
2426
2428
  const isBase58 = (value)=>/^[1-9A-HJ-NP-Za-km-z]+$/.test(value);
2427
2429
  assertMatches(request.chainName === 'SVM' && Boolean(request.chainId) && ((_request_chainId = request.chainId) == null ? void 0 : _request_chainId.trim()) === request.chainId && operation.chainId === request.chainId && request.refreshLimits === undefined && !request.refreshableNonce && intent.limits === undefined && hasLifetime(intent.lifetime, 'blockhash') && (operation.messageVersion === 'legacy' || operation.messageVersion === 'v0') && operation.staticAccountKeys.length > 0 && operation.staticAccountKeys.every(isBase58) && operation.feePayer === request.accountAddress && operation.feePayer === operation.staticAccountKeys[0] && hasValidSvmHeader(intent) && hasValidSvmInstructions(intent), 'Prepared SVM transaction signing intent is malformed');
2428
2430
  };
2431
+ // The intent describes the network in decimal; a request may name it in hexadecimal.
2432
+ const toDecimalChainId = (chainId)=>chainId && /^0x[\da-f]+$/i.test(chainId) ? BigInt(chainId).toString() : chainId;
2433
+ const assertTronTransactionMatchesRequest = (intent, request)=>{
2434
+ const { operation } = intent;
2435
+ // Wallet-service parses the transaction it signs and rejects any mismatch with
2436
+ // the approved operation, so the contract fields are not re-derived here.
2437
+ assertMatches(request.chainName === 'TRON' && Boolean(request.chainId) && operation.chainId === toDecimalChainId(request.chainId) && request.refreshLimits === undefined && !request.refreshableNonce && intent.limits === undefined && hasLifetime(intent.lifetime, 'expiration') && operation.from === request.accountAddress, 'Prepared TRON transaction signing intent is malformed');
2438
+ };
2429
2439
  const assertEvmTransactionMatchesRequest = (intent, request)=>{
2430
2440
  if (request.chainName !== 'EVM') throw new Error('Unsupported transaction signing intent');
2431
2441
  const { operation, limits } = intent;
@@ -2440,28 +2450,24 @@ const assertEvmTransactionMatchesRequest = (intent, request)=>{
2440
2450
  // Wallet-service parses the transaction it signs and rejects any mismatch with
2441
2451
  // the approved operation, so the transaction fields are not re-derived here.
2442
2452
  };
2443
- const assertPreparedSigningIntentMatchesRequest = ({ intent, request, preparedPayload })=>{
2444
- assertMatches(hasMatchingMetadata(intent, request), 'Prepared signing intent does not match request');
2445
- if (intent.operation.kind === 'transaction') {
2446
- if (request.kind !== 'transaction') {
2447
- throw new Error('Unsupported transaction signing intent');
2448
- }
2449
- if (isSvmTransactionIntent(intent)) {
2450
- assertSvmTransactionMatchesRequest(intent, request);
2451
- return;
2452
- }
2453
- if (!isEvmTransactionIntent(intent)) {
2454
- throw new Error('Unsupported transaction signing intent');
2455
- }
2456
- assertEvmTransactionMatchesRequest(intent, request);
2457
- return;
2453
+ const assertTransactionIntentMatchesRequest = (intent, request)=>{
2454
+ if (request.kind !== 'transaction') {
2455
+ throw new Error('Unsupported transaction signing intent');
2458
2456
  }
2457
+ if (isSvmTransactionIntent(intent)) return assertSvmTransactionMatchesRequest(intent, request);
2458
+ if (isTronTransactionIntent(intent)) return assertTronTransactionMatchesRequest(intent, request);
2459
+ if (!isEvmTransactionIntent(intent)) {
2460
+ throw new Error('Unsupported transaction signing intent');
2461
+ }
2462
+ return assertEvmTransactionMatchesRequest(intent, request);
2463
+ };
2464
+ const assertExactOperationMatchesRequest = ({ intent, request, preparedPayload })=>{
2459
2465
  const { operation } = intent;
2460
2466
  assertMatches(preparedPayload !== undefined && operation.payload === preparedPayload, 'Prepared signing intent payload does not match request');
2461
2467
  assertMatches(intent.limits === undefined, 'Exact signing intent cannot include refresh limits');
2462
2468
  assertMatches(hasLifetime(intent.lifetime, undefined), 'Exact signing intent cannot include a lifetime');
2463
2469
  if (operation.kind === 'message') {
2464
- assertMatches(request.kind === 'message' && request.chainName !== 'TRON' && operation.message === request.message, 'Prepared signing intent message does not match request');
2470
+ assertMatches(request.kind === 'message' && operation.message === request.message, 'Prepared signing intent message does not match request');
2465
2471
  return;
2466
2472
  }
2467
2473
  if (operation.kind === 'typedData') {
@@ -2475,5 +2481,17 @@ const assertPreparedSigningIntentMatchesRequest = ({ intent, request, preparedPa
2475
2481
  const rawSign = operation.rawSign;
2476
2482
  assertMatches(request.kind === 'raw' && (rawSign == null ? void 0 : rawSign.payload) === request.rawSign.payload && rawSign.hashFunction === request.rawSign.hashFunction && rawSign.prefix === request.rawSign.prefix, 'Prepared raw signing intent does not match request');
2477
2483
  };
2484
+ const assertPreparedSigningIntentMatchesRequest = ({ intent, request, preparedPayload })=>{
2485
+ assertMatches(hasMatchingMetadata(intent, request), 'Prepared signing intent does not match request');
2486
+ if (isTransactionIntent(intent)) {
2487
+ assertTransactionIntentMatchesRequest(intent, request);
2488
+ return;
2489
+ }
2490
+ assertExactOperationMatchesRequest({
2491
+ intent,
2492
+ request,
2493
+ preparedPayload
2494
+ });
2495
+ };
2478
2496
 
2479
2497
  export { DynamicWalletClient, assertPreparedSigningIntentMatchesRequest, createIframeWaasSDKContainer, preconnectWaasIframe };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/browser-wallet-client",
3
- "version": "1.1.68",
3
+ "version": "1.1.70",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@dynamic-labs-wallet/core": "1.1.68",
7
+ "@dynamic-labs-wallet/core": "1.1.70",
8
8
  "@dynamic-labs/logger": "^5.9.4",
9
9
  "@dynamic-labs/message-transport": "^5.9.1"
10
10
  },
@@ -1 +1 @@
1
- {"version":3,"file":"assertPreparedSigningIntentMatchesRequest.d.ts","sourceRoot":"","sources":["../../packages/src/assertPreparedSigningIntentMatchesRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,2BAA2B,EAAE,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAiHhH,eAAO,MAAM,yCAAyC,0CAInD;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,2BAA2B,CAAC;IACrC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,KAAG,IA6DH,CAAC"}
1
+ {"version":3,"file":"assertPreparedSigningIntentMatchesRequest.d.ts","sourceRoot":"","sources":["../../packages/src/assertPreparedSigningIntentMatchesRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,2BAA2B,EAAE,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAiNhH,eAAO,MAAM,yCAAyC,0CAInD;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,2BAA2B,CAAC;IACrC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,KAAG,IAQH,CAAC"}