@dynamic-labs-wallet/browser-wallet-client 1.1.69 → 1.1.71

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,11 @@ 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';
2405
+ const isBtcTransactionIntent = (intent)=>intent.operation.kind === 'transaction' && intent.operation.chainName === 'BTC';
2403
2406
  const assertMatches = (matches, message)=>{
2404
2407
  if (!matches) throw new Error(message);
2405
2408
  };
@@ -2427,6 +2430,24 @@ const assertSvmTransactionMatchesRequest = (intent, request)=>{
2427
2430
  const isBase58 = (value)=>/^[1-9A-HJ-NP-Za-km-z]+$/.test(value);
2428
2431
  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
2432
  };
2433
+ // The intent describes the network in decimal; a request may name it in hexadecimal.
2434
+ const toDecimalChainId = (chainId)=>chainId && /^0x[\da-f]+$/i.test(chainId) ? BigInt(chainId).toString() : chainId;
2435
+ const assertTronTransactionMatchesRequest = (intent, request)=>{
2436
+ const { operation } = intent;
2437
+ // Wallet-service parses the transaction it signs and rejects any mismatch with
2438
+ // the approved operation, so the contract fields are not re-derived here.
2439
+ 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');
2440
+ };
2441
+ const BTC_HASH = /^[0-9a-f]{64}$/;
2442
+ const DECIMAL = /^(0|[1-9]\d*)$/;
2443
+ const HEX_BYTES = /^(?:[0-9a-f]{2})*$/;
2444
+ const hasValidBtcOperationFields = ({ operation })=>BTC_HASH.test(operation.txid) && DECIMAL.test(operation.feeSats) && Array.isArray(operation.outputs) && operation.outputs.length > 0 && operation.outputs.every(({ script, valueSats })=>HEX_BYTES.test(script) && DECIMAL.test(valueSats)) && Array.isArray(operation.sighashes) && operation.sighashes.length > 0 && operation.sighashes.every((sighash)=>BTC_HASH.test(sighash));
2445
+ const assertBtcTransactionMatchesRequest = (intent, request)=>{
2446
+ var _request_bitcoinConfig;
2447
+ // Wallet-service re-derives the transaction from the PSBT it signs and rejects any
2448
+ // mismatch with the approved operation, so the outputs and hashes are not re-derived here.
2449
+ assertMatches(request.chainName === 'BTC' && intent.operation.chainId === (((_request_bitcoinConfig = request.bitcoinConfig) == null ? void 0 : _request_bitcoinConfig.network) === 'testnet' ? '2' : '1') && request.refreshLimits === undefined && !request.refreshableNonce && intent.limits === undefined && hasLifetime(intent.lifetime, undefined) && hasValidBtcOperationFields(intent), 'Prepared BTC transaction signing intent is malformed');
2450
+ };
2430
2451
  const assertEvmTransactionMatchesRequest = (intent, request)=>{
2431
2452
  if (request.chainName !== 'EVM') throw new Error('Unsupported transaction signing intent');
2432
2453
  const { operation, limits } = intent;
@@ -2441,22 +2462,19 @@ const assertEvmTransactionMatchesRequest = (intent, request)=>{
2441
2462
  // Wallet-service parses the transaction it signs and rejects any mismatch with
2442
2463
  // the approved operation, so the transaction fields are not re-derived here.
2443
2464
  };
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;
2465
+ const assertTransactionIntentMatchesRequest = (intent, request)=>{
2466
+ if (request.kind !== 'transaction') {
2467
+ throw new Error('Unsupported transaction signing intent');
2468
+ }
2469
+ if (isSvmTransactionIntent(intent)) return assertSvmTransactionMatchesRequest(intent, request);
2470
+ if (isTronTransactionIntent(intent)) return assertTronTransactionMatchesRequest(intent, request);
2471
+ if (isBtcTransactionIntent(intent)) return assertBtcTransactionMatchesRequest(intent, request);
2472
+ if (!isEvmTransactionIntent(intent)) {
2473
+ throw new Error('Unsupported transaction signing intent');
2459
2474
  }
2475
+ return assertEvmTransactionMatchesRequest(intent, request);
2476
+ };
2477
+ const assertExactOperationMatchesRequest = ({ intent, request, preparedPayload })=>{
2460
2478
  const { operation } = intent;
2461
2479
  assertMatches(preparedPayload !== undefined && operation.payload === preparedPayload, 'Prepared signing intent payload does not match request');
2462
2480
  assertMatches(intent.limits === undefined, 'Exact signing intent cannot include refresh limits');
@@ -2476,6 +2494,18 @@ const assertPreparedSigningIntentMatchesRequest = ({ intent, request, preparedPa
2476
2494
  const rawSign = operation.rawSign;
2477
2495
  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
2496
  };
2497
+ const assertPreparedSigningIntentMatchesRequest = ({ intent, request, preparedPayload })=>{
2498
+ assertMatches(hasMatchingMetadata(intent, request), 'Prepared signing intent does not match request');
2499
+ if (isTransactionIntent(intent)) {
2500
+ assertTransactionIntentMatchesRequest(intent, request);
2501
+ return;
2502
+ }
2503
+ assertExactOperationMatchesRequest({
2504
+ intent,
2505
+ request,
2506
+ preparedPayload
2507
+ });
2508
+ };
2479
2509
 
2480
2510
  Object.defineProperty(exports, "AuthMode", {
2481
2511
  enumerable: true,
package/index.esm.js CHANGED
@@ -2397,8 +2397,11 @@ 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';
2404
+ const isBtcTransactionIntent = (intent)=>intent.operation.kind === 'transaction' && intent.operation.chainName === 'BTC';
2402
2405
  const assertMatches = (matches, message)=>{
2403
2406
  if (!matches) throw new Error(message);
2404
2407
  };
@@ -2426,6 +2429,24 @@ const assertSvmTransactionMatchesRequest = (intent, request)=>{
2426
2429
  const isBase58 = (value)=>/^[1-9A-HJ-NP-Za-km-z]+$/.test(value);
2427
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');
2428
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
+ };
2440
+ const BTC_HASH = /^[0-9a-f]{64}$/;
2441
+ const DECIMAL = /^(0|[1-9]\d*)$/;
2442
+ const HEX_BYTES = /^(?:[0-9a-f]{2})*$/;
2443
+ const hasValidBtcOperationFields = ({ operation })=>BTC_HASH.test(operation.txid) && DECIMAL.test(operation.feeSats) && Array.isArray(operation.outputs) && operation.outputs.length > 0 && operation.outputs.every(({ script, valueSats })=>HEX_BYTES.test(script) && DECIMAL.test(valueSats)) && Array.isArray(operation.sighashes) && operation.sighashes.length > 0 && operation.sighashes.every((sighash)=>BTC_HASH.test(sighash));
2444
+ const assertBtcTransactionMatchesRequest = (intent, request)=>{
2445
+ var _request_bitcoinConfig;
2446
+ // Wallet-service re-derives the transaction from the PSBT it signs and rejects any
2447
+ // mismatch with the approved operation, so the outputs and hashes are not re-derived here.
2448
+ assertMatches(request.chainName === 'BTC' && intent.operation.chainId === (((_request_bitcoinConfig = request.bitcoinConfig) == null ? void 0 : _request_bitcoinConfig.network) === 'testnet' ? '2' : '1') && request.refreshLimits === undefined && !request.refreshableNonce && intent.limits === undefined && hasLifetime(intent.lifetime, undefined) && hasValidBtcOperationFields(intent), 'Prepared BTC transaction signing intent is malformed');
2449
+ };
2429
2450
  const assertEvmTransactionMatchesRequest = (intent, request)=>{
2430
2451
  if (request.chainName !== 'EVM') throw new Error('Unsupported transaction signing intent');
2431
2452
  const { operation, limits } = intent;
@@ -2440,22 +2461,19 @@ const assertEvmTransactionMatchesRequest = (intent, request)=>{
2440
2461
  // Wallet-service parses the transaction it signs and rejects any mismatch with
2441
2462
  // the approved operation, so the transaction fields are not re-derived here.
2442
2463
  };
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;
2464
+ const assertTransactionIntentMatchesRequest = (intent, request)=>{
2465
+ if (request.kind !== 'transaction') {
2466
+ throw new Error('Unsupported transaction signing intent');
2467
+ }
2468
+ if (isSvmTransactionIntent(intent)) return assertSvmTransactionMatchesRequest(intent, request);
2469
+ if (isTronTransactionIntent(intent)) return assertTronTransactionMatchesRequest(intent, request);
2470
+ if (isBtcTransactionIntent(intent)) return assertBtcTransactionMatchesRequest(intent, request);
2471
+ if (!isEvmTransactionIntent(intent)) {
2472
+ throw new Error('Unsupported transaction signing intent');
2458
2473
  }
2474
+ return assertEvmTransactionMatchesRequest(intent, request);
2475
+ };
2476
+ const assertExactOperationMatchesRequest = ({ intent, request, preparedPayload })=>{
2459
2477
  const { operation } = intent;
2460
2478
  assertMatches(preparedPayload !== undefined && operation.payload === preparedPayload, 'Prepared signing intent payload does not match request');
2461
2479
  assertMatches(intent.limits === undefined, 'Exact signing intent cannot include refresh limits');
@@ -2475,5 +2493,17 @@ const assertPreparedSigningIntentMatchesRequest = ({ intent, request, preparedPa
2475
2493
  const rawSign = operation.rawSign;
2476
2494
  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
2495
  };
2496
+ const assertPreparedSigningIntentMatchesRequest = ({ intent, request, preparedPayload })=>{
2497
+ assertMatches(hasMatchingMetadata(intent, request), 'Prepared signing intent does not match request');
2498
+ if (isTransactionIntent(intent)) {
2499
+ assertTransactionIntentMatchesRequest(intent, request);
2500
+ return;
2501
+ }
2502
+ assertExactOperationMatchesRequest({
2503
+ intent,
2504
+ request,
2505
+ preparedPayload
2506
+ });
2507
+ };
2478
2508
 
2479
2509
  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.69",
3
+ "version": "1.1.71",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@dynamic-labs-wallet/core": "1.1.69",
7
+ "@dynamic-labs-wallet/core": "1.1.71",
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;AAmPhH,eAAO,MAAM,yCAAyC,0CAInD;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,2BAA2B,CAAC;IACrC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,KAAG,IAQH,CAAC"}