@0xsequence/provider 1.1.0 → 1.1.1

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.
@@ -2107,6 +2107,25 @@ function fromExtended(transaction) {
2107
2107
  return [transaction, ...(transaction.auxiliary || [])];
2108
2108
  }
2109
2109
 
2110
+ function validateTransactionRequest(wallet, transaction) {
2111
+ const transactions = core.commons.transaction.fromTransactionish(wallet, transaction);
2112
+ const unwound = core.commons.transaction.unwind(wallet, transactions);
2113
+ unwound.forEach(transaction => validateTransaction(wallet, transaction));
2114
+ }
2115
+ function validateTransaction(wallet, transaction) {
2116
+ if (transaction.to.toLowerCase() === wallet.toLowerCase()) {
2117
+ if (transaction.data) {
2118
+ const data = ethers.ethers.utils.arrayify(transaction.data);
2119
+ if (data.length >= 4) {
2120
+ throw new Error('self calls are forbidden');
2121
+ }
2122
+ }
2123
+ }
2124
+ if (transaction.delegateCall) {
2125
+ throw new Error('delegate calls are forbidden');
2126
+ }
2127
+ }
2128
+
2110
2129
  const SIGNER_READY_TIMEOUT = 10000;
2111
2130
  class WalletRequestHandler {
2112
2131
  constructor(_account, prompter, networks) {
@@ -2297,6 +2316,7 @@ class WalletRequestHandler {
2297
2316
  }
2298
2317
  return tx;
2299
2318
  });
2319
+ validateTransactionRequest(account.address, transactionParams);
2300
2320
  let txnHash = '';
2301
2321
  if (_this.prompter === null) {
2302
2322
  // prompter is null, so we'll send from here
@@ -2322,6 +2342,7 @@ class WalletRequestHandler {
2322
2342
  if (sender !== account.address) {
2323
2343
  throw new Error('sender address does not match wallet');
2324
2344
  }
2345
+ validateTransactionRequest(account.address, transaction);
2325
2346
  if (_this.prompter === null) {
2326
2347
  // The eth_signTransaction method expects a `string` return value we instead return a `SignedTransactions` object,
2327
2348
  // this can only be broadcasted using an RPC provider with support for signed Sequence transactions, like this one.
@@ -2107,6 +2107,25 @@ function fromExtended(transaction) {
2107
2107
  return [transaction, ...(transaction.auxiliary || [])];
2108
2108
  }
2109
2109
 
2110
+ function validateTransactionRequest(wallet, transaction) {
2111
+ const transactions = core.commons.transaction.fromTransactionish(wallet, transaction);
2112
+ const unwound = core.commons.transaction.unwind(wallet, transactions);
2113
+ unwound.forEach(transaction => validateTransaction(wallet, transaction));
2114
+ }
2115
+ function validateTransaction(wallet, transaction) {
2116
+ if (transaction.to.toLowerCase() === wallet.toLowerCase()) {
2117
+ if (transaction.data) {
2118
+ const data = ethers.ethers.utils.arrayify(transaction.data);
2119
+ if (data.length >= 4) {
2120
+ throw new Error('self calls are forbidden');
2121
+ }
2122
+ }
2123
+ }
2124
+ if (transaction.delegateCall) {
2125
+ throw new Error('delegate calls are forbidden');
2126
+ }
2127
+ }
2128
+
2110
2129
  const SIGNER_READY_TIMEOUT = 10000;
2111
2130
  class WalletRequestHandler {
2112
2131
  constructor(_account, prompter, networks) {
@@ -2297,6 +2316,7 @@ class WalletRequestHandler {
2297
2316
  }
2298
2317
  return tx;
2299
2318
  });
2319
+ validateTransactionRequest(account.address, transactionParams);
2300
2320
  let txnHash = '';
2301
2321
  if (_this.prompter === null) {
2302
2322
  // prompter is null, so we'll send from here
@@ -2322,6 +2342,7 @@ class WalletRequestHandler {
2322
2342
  if (sender !== account.address) {
2323
2343
  throw new Error('sender address does not match wallet');
2324
2344
  }
2345
+ validateTransactionRequest(account.address, transaction);
2325
2346
  if (_this.prompter === null) {
2326
2347
  // The eth_signTransaction method expects a `string` return value we instead return a `SignedTransactions` object,
2327
2348
  // this can only be broadcasted using an RPC provider with support for signed Sequence transactions, like this one.
@@ -2103,6 +2103,25 @@ function fromExtended(transaction) {
2103
2103
  return [transaction, ...(transaction.auxiliary || [])];
2104
2104
  }
2105
2105
 
2106
+ function validateTransactionRequest(wallet, transaction) {
2107
+ const transactions = commons.transaction.fromTransactionish(wallet, transaction);
2108
+ const unwound = commons.transaction.unwind(wallet, transactions);
2109
+ unwound.forEach(transaction => validateTransaction(wallet, transaction));
2110
+ }
2111
+ function validateTransaction(wallet, transaction) {
2112
+ if (transaction.to.toLowerCase() === wallet.toLowerCase()) {
2113
+ if (transaction.data) {
2114
+ const data = ethers.utils.arrayify(transaction.data);
2115
+ if (data.length >= 4) {
2116
+ throw new Error('self calls are forbidden');
2117
+ }
2118
+ }
2119
+ }
2120
+ if (transaction.delegateCall) {
2121
+ throw new Error('delegate calls are forbidden');
2122
+ }
2123
+ }
2124
+
2106
2125
  const SIGNER_READY_TIMEOUT = 10000;
2107
2126
  class WalletRequestHandler {
2108
2127
  constructor(_account, prompter, networks) {
@@ -2293,6 +2312,7 @@ class WalletRequestHandler {
2293
2312
  }
2294
2313
  return tx;
2295
2314
  });
2315
+ validateTransactionRequest(account.address, transactionParams);
2296
2316
  let txnHash = '';
2297
2317
  if (_this.prompter === null) {
2298
2318
  // prompter is null, so we'll send from here
@@ -2318,6 +2338,7 @@ class WalletRequestHandler {
2318
2338
  if (sender !== account.address) {
2319
2339
  throw new Error('sender address does not match wallet');
2320
2340
  }
2341
+ validateTransactionRequest(account.address, transaction);
2321
2342
  if (_this.prompter === null) {
2322
2343
  // The eth_signTransaction method expects a `string` return value we instead return a `SignedTransactions` object,
2323
2344
  // this can only be broadcasted using an RPC provider with support for signed Sequence transactions, like this one.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/provider",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "provider sub-package for Sequence",
5
5
  "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
6
6
  "source": "src/index.ts",
@@ -11,15 +11,15 @@
11
11
  "dependencies": {
12
12
  "eventemitter2": "^6.4.5",
13
13
  "webextension-polyfill": "^0.10.0",
14
- "@0xsequence/abi": "1.1.0",
15
- "@0xsequence/account": "1.1.0",
16
- "@0xsequence/auth": "1.1.0",
17
- "@0xsequence/relayer": "1.1.0",
18
- "@0xsequence/migration": "1.1.0",
19
- "@0xsequence/core": "1.1.0",
20
- "@0xsequence/network": "1.1.0",
21
- "@0xsequence/wallet": "1.1.0",
22
- "@0xsequence/utils": "1.1.0"
14
+ "@0xsequence/account": "1.1.1",
15
+ "@0xsequence/abi": "1.1.1",
16
+ "@0xsequence/auth": "1.1.1",
17
+ "@0xsequence/core": "1.1.1",
18
+ "@0xsequence/migration": "1.1.1",
19
+ "@0xsequence/network": "1.1.1",
20
+ "@0xsequence/relayer": "1.1.1",
21
+ "@0xsequence/utils": "1.1.1",
22
+ "@0xsequence/wallet": "1.1.1"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "ethers": ">=5.5 < 6"
@@ -0,0 +1,23 @@
1
+ import { commons } from '@0xsequence/core'
2
+ import { ethers } from 'ethers'
3
+
4
+ export function validateTransactionRequest(wallet: string, transaction: commons.transaction.Transactionish) {
5
+ const transactions = commons.transaction.fromTransactionish(wallet, transaction)
6
+ const unwound = commons.transaction.unwind(wallet, transactions)
7
+ unwound.forEach(transaction => validateTransaction(wallet, transaction))
8
+ }
9
+
10
+ function validateTransaction(wallet: string, transaction: commons.transaction.Transaction) {
11
+ if (transaction.to.toLowerCase() === wallet.toLowerCase()) {
12
+ if (transaction.data) {
13
+ const data = ethers.utils.arrayify(transaction.data)
14
+ if (data.length >= 4) {
15
+ throw new Error('self calls are forbidden')
16
+ }
17
+ }
18
+ }
19
+
20
+ if (transaction.delegateCall) {
21
+ throw new Error('delegate calls are forbidden')
22
+ }
23
+ }
@@ -7,6 +7,7 @@ import { BigNumber, ethers, providers } from 'ethers'
7
7
  import { EventEmitter2 as EventEmitter } from 'eventemitter2'
8
8
 
9
9
  import { fromExtended } from '../extended'
10
+ import { validateTransactionRequest } from '../transactions'
10
11
  import {
11
12
  ProviderMessageRequest,
12
13
  ProviderMessageResponse,
@@ -393,6 +394,8 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
393
394
  return tx
394
395
  })
395
396
 
397
+ validateTransactionRequest(account.address, transactionParams)
398
+
396
399
  let txnHash = ''
397
400
  if (this.prompter === null) {
398
401
  // prompter is null, so we'll send from here
@@ -421,6 +424,8 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
421
424
  throw new Error('sender address does not match wallet')
422
425
  }
423
426
 
427
+ validateTransactionRequest(account.address, transaction)
428
+
424
429
  if (this.prompter === null) {
425
430
  // The eth_signTransaction method expects a `string` return value we instead return a `SignedTransactions` object,
426
431
  // this can only be broadcasted using an RPC provider with support for signed Sequence transactions, like this one.