Skip to content
Draft
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
1 change: 1 addition & 0 deletions packages/tron-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **BREAKING** Implement Keyring API v2 (`KeyringSnapRpc` interface): rename `listAccounts` → `getAccounts`, `listAccountAssets` → `getAccountAssets`, `listAccountTransactions` → `getAccountTransactions`; `getAccount` now throws instead of returning `undefined`; add `exportAccount` with hexadecimal private key export using `sensitive()` for redaction; remove v1-only methods `createAccount`, `discoverAccounts`, `filterAccountChains`, and `updateAccount`. ([#56](https://github.com/MetaMask/internal-snaps/pull/56))
- Add `bip44:discover` support to `createAccounts`: checks on-chain activity across all Tron networks before persisting; returns `[]` if no activity to signal end-of-discovery to the client. ([#56](https://github.com/MetaMask/internal-snaps/pull/56))
- Add `endowment:keyring` capabilities to manifest declaring the `tron:728126428` scope, hexadecimal private key export, and BIP-44 derivation strategies. ([#56](https://github.com/MetaMask/internal-snaps/pull/56))
- Wire Core messenger endowment and instantiate `RemoteFeatureFlagsProvider` and `AssetsProvider` from `@metamask/snap-networks-utils` v1.0.0 (plumbing only; no Core routing yet).

### Fixed

Expand Down
4 changes: 4 additions & 0 deletions packages/tron-wallet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"devDependencies": {
"@metamask/assets-controller": "^13.0.0",
"@metamask/auto-changelog": "^6.1.1",
"@metamask/key-tree": "^10.1.1",
"@metamask/keyring-api": "^23.7.0",
"@metamask/keyring-snap-sdk": "^9.2.1",
"@metamask/messenger": "^2.0.0",
"@metamask/remote-feature-flag-controller": "4.2.2",
"@metamask/snap-networks-utils": "workspace:^",
"@metamask/snaps-cli": "^8.4.1",
"@metamask/snaps-jest": "^10.2.0",
"@metamask/snaps-sdk": "^11.2.0",
Expand Down
10 changes: 9 additions & 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": "TEEXgH0mFwQ1x70iGzw0kNN7P/lPzIiLa+ATCM2v/vY=",
"shasum": "K7bx3ON8enrNS41Zaa7mCpiK5jmUOoo4DerjiQ3VmDw=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down Expand Up @@ -63,6 +63,14 @@
},
"endowment:assets": {
"scopes": ["tron:728126428"]
},
"endowment:messenger": {
"actions": [
"RemoteFeatureFlagController:getState",
"AssetsController:getAccountAssetByID",
"AssetsController:getAccountAssetsByIDs",
"AssetsController:getAccountAssetsByScope"
]
}
},
"platformVersion": "11.2.0",
Expand Down
30 changes: 29 additions & 1 deletion packages/tron-wallet-snap/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { getMessenger } from '@metamask/snaps-sdk';
import {
AssetsProvider,
RemoteFeatureFlagsProvider,
type AssetsProviderMessenger,
type RemoteFeatureFlagsProviderMessenger,
} from '@metamask/snap-networks-utils';

import { InMemoryCache } from './caching/InMemoryCache';
import { StateCache } from './caching/StateCache';
import { PriceApiClient } from './clients/price-api/PriceApiClient';
Expand Down Expand Up @@ -29,6 +37,7 @@ import { TransactionScanService } from './services/transaction-scan/TransactionS
import { TransactionsRepository } from './services/transactions/TransactionsRepository';
import { TransactionsService } from './services/transactions/TransactionsService';
import { WalletService } from './services/wallet/WalletService';
import type { CoreMessenger, CoreMessengerMessenger } from './types/core-messenger';
import logger, { noOpLogger } from './utils/logger';

/**
Expand Down Expand Up @@ -82,13 +91,23 @@ const priceApiClient = new PriceApiClient(configProvider, priceCache);
// Token API client
const tokenApiClient = new TokenApiClient(configProvider);

const coreMessenger = getMessenger<CoreMessengerMessenger>();

const remoteFeatureFlagsProvider = new RemoteFeatureFlagsProvider({
messenger: coreMessenger as RemoteFeatureFlagsProviderMessenger,
});

const assetsProvider = new AssetsProvider({
messenger: coreMessenger as AssetsProviderMessenger,
});

// Security Alerts API client
const securityAlertsApiClient = new SecurityAlertsApiClient(
configProvider,
logger,
);

// Business Services - depend on Repositories, State and other Services
// Business Services
const assetsService = new AssetsService({
logger,
state,
Expand Down Expand Up @@ -235,6 +254,12 @@ export type SnapExecutionContext = {
confirmationHandler: ConfirmationHandler;
transactionScanService: TransactionScanService;
transactionExpirationRefresherService: TransactionExpirationRefresherService;
/**
* Core messenger plumbing (routing wired in a follow-up PR).
*/
coreMessenger: CoreMessenger;
remoteFeatureFlagsProvider: RemoteFeatureFlagsProvider;
assetsProvider: AssetsProvider;
/**
* Handlers
*/
Expand Down Expand Up @@ -267,6 +292,9 @@ const snapContext: SnapExecutionContext = {
confirmationHandler,
transactionScanService,
transactionExpirationRefresherService,
coreMessenger,
remoteFeatureFlagsProvider,
assetsProvider,
/**
* Handlers
*/
Expand Down
34 changes: 34 additions & 0 deletions packages/tron-wallet-snap/src/types/core-messenger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type {
AssetsControllerGetAccountAssetByIDAction,
AssetsControllerGetAccountAssetsByIDsAction,
AssetsControllerGetAccountAssetsByScopeAction,
} from '@metamask/assets-controller';
import type { Messenger } from '@metamask/messenger';
import type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';
import type { AsyncMessenger } from '@metamask/snaps-sdk';

/**
* Namespace for this Snap's Core messenger endowment.
*/
export const TRON_WALLET_SNAP_MESSENGER_NAMESPACE =
'TronWalletSnap' as const;

export type CoreMessengerActions =
| RemoteFeatureFlagControllerGetStateAction
| AssetsControllerGetAccountAssetByIDAction
| AssetsControllerGetAccountAssetsByIDsAction
| AssetsControllerGetAccountAssetsByScopeAction;

/**
* Messenger type passed to `getMessenger` for Core controller actions.
*/
export type CoreMessengerMessenger = Messenger<
typeof TRON_WALLET_SNAP_MESSENGER_NAMESPACE,
CoreMessengerActions
>;

/**
* Typed async messenger for Core controller actions available to this Snap via
* `endowment:messenger` / `getMessenger`.
*/
export type CoreMessenger = AsyncMessenger<CoreMessengerMessenger>;
21 changes: 19 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ __metadata:
languageName: node
linkType: hard

"@metamask/controller-utils@npm:^12.0.0, @metamask/controller-utils@npm:^12.3.0":
"@metamask/controller-utils@npm:^12.0.0, @metamask/controller-utils@npm:^12.1.0, @metamask/controller-utils@npm:^12.3.0":
version: 12.3.0
resolution: "@metamask/controller-utils@npm:12.3.0"
dependencies:
Expand Down Expand Up @@ -3208,6 +3208,19 @@ __metadata:
languageName: node
linkType: hard

"@metamask/remote-feature-flag-controller@npm:4.2.2":
version: 4.2.2
resolution: "@metamask/remote-feature-flag-controller@npm:4.2.2"
dependencies:
"@metamask/base-controller": "npm:^9.1.0"
"@metamask/controller-utils": "npm:^12.1.0"
"@metamask/messenger": "npm:^1.2.0"
"@metamask/utils": "npm:^11.9.0"
uuid: "npm:^8.3.2"
checksum: 10/ed03ff1ba63c7a0f2b221c3514eb71a8be4200ec543b90676a44930dc731920ac2c92dcc2b13a32ed4e4e8e7e7b28a26db443af9f4bf30f5e2b5785580b286ab
languageName: node
linkType: hard

"@metamask/remote-feature-flag-controller@npm:^5.0.0":
version: 5.0.0
resolution: "@metamask/remote-feature-flag-controller@npm:5.0.0"
Expand Down Expand Up @@ -3292,7 +3305,7 @@ __metadata:
languageName: node
linkType: hard

"@metamask/snap-networks-utils@workspace:packages/snap-networks-utils":
"@metamask/snap-networks-utils@workspace:^, @metamask/snap-networks-utils@workspace:packages/snap-networks-utils":
version: 0.0.0-use.local
resolution: "@metamask/snap-networks-utils@workspace:packages/snap-networks-utils"
dependencies:
Expand Down Expand Up @@ -3717,10 +3730,14 @@ __metadata:
version: 0.0.0-use.local
resolution: "@metamask/tron-wallet-snap@workspace:packages/tron-wallet-snap"
dependencies:
"@metamask/assets-controller": "npm:^13.0.0"
"@metamask/auto-changelog": "npm:^6.1.1"
"@metamask/key-tree": "npm:^10.1.1"
"@metamask/keyring-api": "npm:^23.7.0"
"@metamask/keyring-snap-sdk": "npm:^9.2.1"
"@metamask/messenger": "npm:^2.0.0"
"@metamask/remote-feature-flag-controller": "npm:4.2.2"
"@metamask/snap-networks-utils": "workspace:^"
"@metamask/snaps-cli": "npm:^8.4.1"
"@metamask/snaps-jest": "npm:^10.2.0"
"@metamask/snaps-sdk": "npm:^11.2.0"
Expand Down
Loading