Skip to content
Closed
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
7 changes: 4 additions & 3 deletions packages/tron-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ 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).
- Route asset reads through the shared `AssetsProvider` from `@metamask/snap-networks-utils` using account-scoped `AssetsController:getAccountAssetByID`, `AssetsController:getAccountAssetsByIDs`, and `AssetsController:getAccountAssetsByScope` actions when the migration stage is not `Off`. Snap-owned assets remain synced by the Snap but are read through the same controller path as fungibles. Resolution order: remote feature flags → Off default.

### Fixed
### Changed

- Fix `bip44:discover` always failing due to `Network` enum being compiled bidirectionally by TypeScript when initialised from another enum's members, causing `Object.values(Network)` to include human-readable names (`"Mainnet"` etc.) alongside scope IDs; replaced enum initialisers with string literals so TypeScript emits a one-way mapping. ([#101](https://github.com/MetaMask/internal-snaps/pull/101))
- Fix `submitRequest` returning a v1 `KeyringResponse` envelope `{ pending: false, result: ... }` instead of raw `Json`; the Keyring API v2 `SnapKeyring` calls the snap directly and expects unwrapped `Json` back. ([#105](https://github.com/MetaMask/internal-snaps/pull/105))
- Update `snap.manifest.json` bundle shasum ([#82](https://github.com/MetaMask/internal-snaps/pull/82))

## [2.0.0]

Expand Down
9 changes: 8 additions & 1 deletion packages/tron-wallet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,23 @@
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@metamask/snap-networks-utils": "workspace:^"
},
"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",
"@metamask/superstruct": "^3.4.1",
"@types/lodash": "^4.17.15",
"@types/lodash": "^4.14.191",
"async-mutex": "^0.5.0",
"bignumber.js": "^9.3.1",
"concurrently": "^10.0.3",
Expand Down
27 changes: 10 additions & 17 deletions 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": "uocZF1RsEzCWGmRM3X3mMv42laNfJWpwVXOfNViikl8=",
"shasum": "m1aV5aLS2glLsXdoHzUjoFUieyH4oUKiyzocw5VdWXY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -23,22 +23,7 @@
},
"initialPermissions": {
"endowment:keyring": {
"allowedOrigins": ["https://portfolio.metamask.io"],
"capabilities": {
"scopes": ["tron:728126428"],
"privateKey": {
"exportFormats": [
{
"encoding": "hexadecimal"
}
]
},
"bip44": {
"deriveIndex": true,
"deriveIndexRange": true,
"discover": true
}
}
"allowedOrigins": ["https://portfolio.metamask.io"]
},
"snap_getBip32Entropy": [
{
Expand All @@ -63,6 +48,14 @@
},
"endowment:assets": {
"scopes": ["tron:728126428"]
},
"endowment:messenger": {
"actions": [
"AssetsController:getAccountAssetByID",
"AssetsController:getAccountAssetsByIDs",
"AssetsController:getAccountAssetsByScope",
"RemoteFeatureFlagController:getState"
]
}
},
"platformVersion": "11.2.0",
Expand Down
32 changes: 31 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 All @@ -98,6 +117,8 @@ const assetsService = new AssetsService({
priceApiClient,
tokenApiClient,
snapClient,
coreMessenger,
assetsProvider,
});

const transactionsService = new TransactionsService({
Expand Down Expand Up @@ -235,6 +256,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 +294,9 @@ const snapContext: SnapExecutionContext = {
confirmationHandler,
transactionScanService,
transactionExpirationRefresherService,
coreMessenger,
remoteFeatureFlagsProvider,
assetsProvider,
/**
* Handlers
*/
Expand Down
10 changes: 8 additions & 2 deletions packages/tron-wallet-snap/src/handlers/keyring/keyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ describe('KeyringHandler', () => {

const result = await keyringHandler.submitRequest(request);

expect(result).toStrictEqual({ signature: '0xsignature123' });
expect(result).toStrictEqual({
pending: false,
result: { signature: '0xsignature123' },
});
expect(mockAccountsService.findById).toHaveBeenCalledWith(
mockAccount.id,
);
Expand Down Expand Up @@ -221,7 +224,10 @@ describe('KeyringHandler', () => {

const result = await keyringHandler.submitRequest(request);

expect(result).toStrictEqual({ signature: '0xsignature123' });
expect(result).toStrictEqual({
pending: false,
result: { signature: '0xsignature123' },
});
// The request reaching confirmation keeps the dApp's original payload.
expect(
mockConfirmationHandler.handleKeyringRequest,
Expand Down
5 changes: 3 additions & 2 deletions packages/tron-wallet-snap/src/handlers/keyring/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
CreateAccountOptions as KeyringBatchCreateAccountOptions,
KeyringAccount,
KeyringRequest,
KeyringResponse,
Pagination,
ResolvedAccountAddress,
Transaction,
Expand Down Expand Up @@ -395,8 +396,8 @@ export class KeyringHandler implements KeyringSnapRpc {
}
}

async submitRequest(request: KeyringRequest): Promise<Json> {
return this.#handleSubmitRequest(request);
async submitRequest(request: KeyringRequest): Promise<KeyringResponse> {
return { pending: false, result: await this.#handleSubmitRequest(request) };
}

#prepareRequestForConfirmation(
Expand Down
Loading
Loading