Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/tron-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add Core messenger plumbing (`getMessenger`, `RemoteFeatureFlagsProvider`, `AssetsProvider`) for upcoming AssetsController migration ([#95](https://github.com/MetaMask/internal-snaps/pull/95))

### Fixed

- Scope `bip44:discover` activity checks and account creation to the networks declared in the snap manifest, preventing unnecessary calls to testnet APIs during discovery ([#135](https://github.com/MetaMask/internal-snaps/pull/135))

## [3.0.0]

### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/tron-wallet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/internal-snaps.git"
},
"source": {
"shasum": "B9kqmuUcYgPAD3ojseIm2HymqK77Q4NEzULU876+5Wc=",
"shasum": "C13HWdtafD3wHLxY5EH6CQlnUuu8RQoe1YcaTX+P+rE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
AccountCreationType,
KeyringEvent,
TrxAccountType,
TrxScope,
} from '@metamask/keyring-api';
import {
emitSnapKeyringEvent,
Expand All @@ -30,7 +29,7 @@ import type { ConfigProvider } from '../config';
import type { Config } from '../config/ConfigProvider';
import type { TransactionsService } from '../transactions/TransactionsService';
import type { AccountsRepository } from './AccountsRepository';
import { AccountsService } from './AccountsService';
import { AccountsService, SUPPORTED_SCOPES } from './AccountsService';

jest.mock('@metamask/keyring-snap-sdk', () => ({
emitSnapKeyringEvent: jest.fn(),
Expand Down Expand Up @@ -333,7 +332,7 @@ describe('AccountsService', () => {
derivationPath: "m/44'/195'/0'/0/0",
index: 0,
type: TrxAccountType.Eoa,
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES,
methods: ['signMessage', 'signTransaction'],
});
expect(result.id).toBeDefined();
Expand Down Expand Up @@ -483,7 +482,7 @@ describe('AccountsService', () => {
index: 0,
type: TrxAccountType.Eoa,
address: 'TConcurrent0',
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to cast here because there's a mismatch between the readonly Network[] type and KeyringAccount's scopes property. I'm going to review usage of the property across our architecture and possibly tighten the type upstream.

options: {},
methods: ['signMessage', 'signTransaction'],
};
Expand Down Expand Up @@ -516,7 +515,7 @@ describe('AccountsService', () => {
index: 0,
type: TrxAccountType.Eoa,
address: 'TExisting0',
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {},
methods: ['signMessage', 'signTransaction'],
};
Expand All @@ -527,7 +526,7 @@ describe('AccountsService', () => {
index: 1,
type: TrxAccountType.Eoa,
address: 'TExisting1',
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {},
methods: ['signMessage', 'signTransaction'],
};
Expand Down Expand Up @@ -636,9 +635,9 @@ describe('AccountsService', () => {
mockAccountsRepository,
mockTransactionsService,
}) => {
mockTransactionsService.checkAddressActivity
.mockResolvedValueOnce(false)
.mockResolvedValueOnce(true);
mockTransactionsService.checkAddressActivity.mockResolvedValueOnce(
true,
);

const result = await accountsService.createAccounts({
type: AccountCreationType.Bip44Discover,
Expand Down Expand Up @@ -673,7 +672,7 @@ describe('AccountsService', () => {
index: 0,
type: TrxAccountType.Eoa,
address: 'TTestAddress1234567890123456789',
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {
entropy: {
type: 'mnemonic',
Expand Down Expand Up @@ -716,7 +715,7 @@ describe('AccountsService', () => {
index: 0,
type: TrxAccountType.Eoa,
address: 'TExistingDefault0',
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {},
methods: ['signMessage', 'signTransaction'],
};
Expand All @@ -733,7 +732,7 @@ describe('AccountsService', () => {
index: 1,
type: TrxAccountType.Eoa,
address: 'TDefaultCreate1',
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {
entropy: {
type: 'mnemonic',
Expand Down Expand Up @@ -769,7 +768,7 @@ describe('AccountsService', () => {
index: 0,
type: TrxAccountType.Eoa,
address: 'TExisting123456789012345678901',
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {},
methods: ['signMessage', 'signTransaction'],
};
Expand Down Expand Up @@ -804,7 +803,7 @@ describe('AccountsService', () => {
index: 0,
type: TrxAccountType.Eoa,
address: 'TRollback12345678901234567890',
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {
entropy: {
type: 'mnemonic',
Expand Down Expand Up @@ -849,7 +848,7 @@ describe('AccountsService', () => {
index: 0,
type: TrxAccountType.Eoa,
address: 'TRollback12345678901234567890',
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {
entropy: {
type: 'mnemonic',
Expand Down Expand Up @@ -892,7 +891,7 @@ describe('AccountsService', () => {
index: 0,
type: TrxAccountType.Eoa,
address: 'TMeta1234567890123456789012',
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {},
methods: ['signMessage', 'signTransaction'],
});
Expand Down Expand Up @@ -921,7 +920,7 @@ describe('AccountsService', () => {
index: 0,
type: TrxAccountType.Eoa,
address: 'TConflict12345678901234567890',
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {},
methods: ['signMessage', 'signTransaction'],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
assertCreateAccountOptionIsSupported,
KeyringEvent,
TrxAccountType,
TrxScope,
} from '@metamask/keyring-api';
import {
emitSnapKeyringEvent,
Expand All @@ -21,6 +20,7 @@ import { hexToBytes } from '@metamask/utils';
import { computeAddress } from 'ethers';
import { TronWeb } from 'tronweb';

import snapManifest from '../../../snap.manifest.json';
import type { SnapClient } from '../../clients/snap/SnapClient';
import { Network } from '../../constants';
import { asStrictKeyringAccount } from '../../entities/keyring-account';
Expand All @@ -47,6 +47,10 @@ const CURVE = 'secp256k1' as const;
*/
const MAX_BIP44_ACCOUNT_INDEX = 0x7fffffff;

export const SUPPORTED_SCOPES = snapManifest.initialPermissions[
'endowment:keyring'
].capabilities.scopes as readonly Network[];

/**
* Range of inclusive account indices to create.
*
Expand Down Expand Up @@ -217,7 +221,7 @@ export class AccountsService {
index,
type: TrxAccountType.Eoa,
address,
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {
entropy: {
type: 'mnemonic',
Expand Down Expand Up @@ -357,7 +361,7 @@ export class AccountsService {
index: groupIndex,
});
const activityChecks = await Promise.all(
Object.values(Network).map((scope) =>
SUPPORTED_SCOPES.map((scope) =>
this.#transactionsService.checkAddressActivity(
scope,
derivedAccount.address,
Expand Down Expand Up @@ -418,7 +422,7 @@ export class AccountsService {
index: groupIndex,
type: TrxAccountType.Eoa,
address,
scopes: [TrxScope.Mainnet, TrxScope.Nile, TrxScope.Shasta],
scopes: SUPPORTED_SCOPES as unknown as Network[],
options: {
entropy: {
type: 'mnemonic',
Expand Down