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
5 changes: 0 additions & 5 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,6 @@
"count": 2
}
},
"packages/solana-wallet-snap/src/core/services/send/types.ts": {
"@typescript-eslint/no-shadow": {
"count": 1
}
},
"packages/solana-wallet-snap/src/core/services/signer/Signer.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 1
Expand Down
2 changes: 1 addition & 1 deletion packages/solana-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": "5FfpznC3zSm/PzcS3bNGu1a/heN2o1uLIfoc/y3xpMc=",
"shasum": "Q2MJMblB+y+GZbCWcaoI0QUB2pNN1JfiWP/y05hBg7g=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export class TokenApiClient {
// The Token API only supports the networks in TokenApiClient.supportedNetworks
const supportedAssetTypes = assetTypes.filter((assetType) => {
const { chainId } = parseCaipAssetType(assetType);
return TokenApiClient.supportedNetworks.includes(chainId as Network);
return TokenApiClient.supportedNetworks.includes(
chainId as (typeof TokenApiClient.supportedNetworks)[number],
);
});

if (supportedAssetTypes.length !== assetTypes.length) {
Expand Down
53 changes: 30 additions & 23 deletions packages/solana-wallet-snap/src/core/constants/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,30 @@ export const METAMASK_ORIGIN_URL = 'https://metamask.io';
*
* @see https://namespaces.chainagnostic.org/solana/caip2
*/
export enum Network {
Mainnet = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
Devnet = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
Testnet = 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',
Localnet = 'solana:123456789abcdef',
}

export enum KnownCaip19Id {
SolMainnet = `${Network.Mainnet}/slip44:501`,
SolDevnet = `${Network.Devnet}/slip44:501`,
SolTestnet = `${Network.Testnet}/slip44:501`,
SolLocalnet = `${Network.Localnet}/slip44:501`,
UsdcMainnet = `${Network.Mainnet}/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`,
UsdcDevnet = `${Network.Devnet}/token:4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU`,
UsdcLocalnet = `${Network.Localnet}/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`,
EurcMainnet = `${Network.Mainnet}/token:HzwqbKZw8HxMN6bF2yFZNrht3c2iXXzpKcFu7uBEDKtr`,
EurcDevnet = `${Network.Devnet}/token:HzwqbKZw8HxMN6bF2yFZNrht3c2iXXzpKcFu7uBEDKtr`,
EurcLocalnet = `${Network.Localnet}/token:HzwqbKZw8HxMN6bF2yFZNrht3c2iXXzpKcFu7uBEDKtr`,
Ai16zMainnet = `${Network.Mainnet}/token:HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC`,
}
export const Network = {
Mainnet: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
Devnet: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
Testnet: 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',
Localnet: 'solana:123456789abcdef',
} as const;

export type Network = (typeof Network)[keyof typeof Network];

export const KnownCaip19Id = {
SolMainnet: `${Network.Mainnet}/slip44:501`,
SolDevnet: `${Network.Devnet}/slip44:501`,
SolTestnet: `${Network.Testnet}/slip44:501`,
SolLocalnet: `${Network.Localnet}/slip44:501`,
UsdcMainnet: `${Network.Mainnet}/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`,
UsdcDevnet: `${Network.Devnet}/token:4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU`,
UsdcLocalnet: `${Network.Localnet}/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`,
EurcMainnet: `${Network.Mainnet}/token:HzwqbKZw8HxMN6bF2yFZNrht3c2iXXzpKcFu7uBEDKtr`,
EurcDevnet: `${Network.Devnet}/token:HzwqbKZw8HxMN6bF2yFZNrht3c2iXXzpKcFu7uBEDKtr`,
EurcLocalnet: `${Network.Localnet}/token:HzwqbKZw8HxMN6bF2yFZNrht3c2iXXzpKcFu7uBEDKtr`,
Ai16zMainnet: `${Network.Mainnet}/token:HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC`,
} as const;

export type KnownCaip19Id = (typeof KnownCaip19Id)[keyof typeof KnownCaip19Id];

export type NativeCaipAssetType = `${Network}/slip44:501`;
export type TokenCaipAssetType = `${Network}/token:${string}`;
Expand Down Expand Up @@ -92,9 +96,12 @@ export const NETWORK_TO_EXPLORER_CLUSTER = {
[Network.Localnet]: 'local',
};

export enum SolanaCaip19Tokens {
SOL = 'slip44:501',
}
export const SolanaCaip19Tokens = {
SOL: 'slip44:501',
} as const;

export type SolanaCaip19Tokens =
(typeof SolanaCaip19Tokens)[keyof typeof SolanaCaip19Tokens];

export type TokenInfo = {
symbol: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
export enum ClientRequestMethod {
SignAndSendTransactionWithoutConfirmation = 'signAndSendTransactionWithoutConfirmation',
ConfirmSend = 'confirmSend',
SignAndSendTransaction = 'signAndSendTransaction',
ComputeFee = 'computeFee',
OnAddressInput = 'onAddressInput',
OnAmountInput = 'onAmountInput',
SignRewardsMessage = 'signRewardsMessage',
SignCardMessage = 'signCardMessage',
ApproveCardAmount = 'approveCardAmount',
SignProofOfOwnership = 'signProofOfOwnership',
}
export const ClientRequestMethod = {
SignAndSendTransactionWithoutConfirmation:
'signAndSendTransactionWithoutConfirmation',
ConfirmSend: 'confirmSend',
SignAndSendTransaction: 'signAndSendTransaction',
ComputeFee: 'computeFee',
OnAddressInput: 'onAddressInput',
OnAmountInput: 'onAmountInput',
SignRewardsMessage: 'signRewardsMessage',
SignCardMessage: 'signCardMessage',
ApproveCardAmount: 'approveCardAmount',
SignProofOfOwnership: 'signProofOfOwnership',
} as const;

export type ClientRequestMethod =
(typeof ClientRequestMethod)[keyof typeof ClientRequestMethod];
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
export enum ScheduleBackgroundEventMethod {
export const ScheduleBackgroundEventMethod = {
/** Triggered when a transaction is shown in confirmation UI */
OnTransactionAdded = 'onTransactionAdded',
OnTransactionAdded: 'onTransactionAdded',
/** Triggered when the user confirms a transaction in the confirmation UI */
OnTransactionApproved = 'onTransactionApproved',
OnTransactionApproved: 'onTransactionApproved',
/** Triggered when a transaction is rejected */
OnTransactionRejected = 'onTransactionRejected',
OnTransactionRejected: 'onTransactionRejected',
/** Use it to schedule a background event to refresh the confirmation estimation */
RefreshConfirmationEstimation = 'refreshConfirmationEstimation',
RefreshConfirmationEstimation: 'refreshConfirmationEstimation',
/** Use it to schedule a background event to close WebSocket connections */
CloseWebSocketConnections = 'closeWebSocketConnections',
}
CloseWebSocketConnections: 'closeWebSocketConnections',
} as const;

export type ScheduleBackgroundEventMethod =
(typeof ScheduleBackgroundEventMethod)[keyof typeof ScheduleBackgroundEventMethod];
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export enum CronjobMethod {}
export const CronjobMethod = {} as const;

export type CronjobMethod = (typeof CronjobMethod)[keyof typeof CronjobMethod];
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import {
} from '@metamask/superstruct';
import { JsonRpcIdStruct, JsonRpcVersionStruct } from '@metamask/utils';

export enum SolanaProtocolRequestMethod {
GetGenesisHash = 'getGenesisHash',
GetLatestBlockhash = 'getLatestBlockhash',
GetMinimumBalanceForRentExemption = 'getMinimumBalanceForRentExemption',
}
export const SolanaProtocolRequestMethod = {
GetGenesisHash: 'getGenesisHash',
GetLatestBlockhash: 'getLatestBlockhash',
GetMinimumBalanceForRentExemption: 'getMinimumBalanceForRentExemption',
} as const;

export type SolanaProtocolRequestMethod =
(typeof SolanaProtocolRequestMethod)[keyof typeof SolanaProtocolRequestMethod];

export const SolanaGetGenesisHashRequestStruct = object({
jsonrpc: JsonRpcVersionStruct,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
* Methods specific to the test dapp,
* to allow specific flows for manual testing.
*/
export enum TestDappRpcRequestMethod {
ListWebSockets = 'listWebSockets',
ListSubscriptions = 'listSubscriptions',
TestOnStart = 'testOnStart',
TestOnInstall = 'testOnInstall',
TestOnUpdate = 'testOnUpdate',
SynchronizeAccounts = 'synchronizeAccounts',
SetAccountSelected = 'setAccountSelected',
ConfirmSend = 'confirmSend',
SignRewardsMessage = 'signRewardsMessage',
}
export const TestDappRpcRequestMethod = {
ListWebSockets: 'listWebSockets',
ListSubscriptions: 'listSubscriptions',
TestOnStart: 'testOnStart',
TestOnInstall: 'testOnInstall',
TestOnUpdate: 'testOnUpdate',
SynchronizeAccounts: 'synchronizeAccounts',
SetAccountSelected: 'setAccountSelected',
ConfirmSend: 'confirmSend',
SignRewardsMessage: 'signRewardsMessage',
} as const;

export type TestDappRpcRequestMethod =
(typeof TestDappRpcRequestMethod)[keyof typeof TestDappRpcRequestMethod];
15 changes: 9 additions & 6 deletions packages/solana-wallet-snap/src/core/services/send/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ export type OnAmountInputRequest = Infer<typeof OnAmountInputRequestStruct>;

export type ValidationResponse = Infer<typeof ValidationResponseStruct>;

export enum SendErrorCodes {
Required = 'Required',
Invalid = 'Invalid',
InsufficientBalanceToCoverFee = 'InsufficientBalanceToCoverFee',
InsufficientBalance = 'InsufficientBalance',
}
export const SendErrorCodes = {
Required: 'Required',
Invalid: 'Invalid',
InsufficientBalanceToCoverFee: 'InsufficientBalanceToCoverFee',
InsufficientBalance: 'InsufficientBalance',
} as const;

export type SendErrorCodes =
(typeof SendErrorCodes)[keyof typeof SendErrorCodes];
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const mockConnectionId = 'mock-connection-id';
const createMockWebSocketConnection = (
id = mockConnectionId,
url = mockWebSocketUrl,
network = Network.Mainnet,
network: Network = Network.Mainnet,
): WebSocketConnection => ({
id,
url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ export type TransactionScanResult = {
error: TransactionScanError | null;
};

export enum SecurityAlertResponse {
Benign = 'Benign',
Warning = 'Warning',
Malicious = 'Malicious',
}

export enum ScanStatus {
SUCCESS = 'SUCCESS',
ERROR = 'ERROR',
}
export const SecurityAlertResponse = {
Benign: 'Benign',
Warning: 'Warning',
Malicious: 'Malicious',
} as const;

export type SecurityAlertResponse =
(typeof SecurityAlertResponse)[keyof typeof SecurityAlertResponse];

export const ScanStatus = {
SUCCESS: 'SUCCESS',
ERROR: 'ERROR',
} as const;

export type ScanStatus = (typeof ScanStatus)[keyof typeof ScanStatus];
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ export const SECP256R1_PROGRAM_ADDRESS = address(
'Secp256r1SigVerify1111111111111111111111111',
);

export enum Secp256Instruction {
Verify = 0,
}
export const Secp256Instruction = {
Verify: 0,
} as const;

export type Secp256Instruction =
(typeof Secp256Instruction)[keyof typeof Secp256Instruction];

export const identifySecp256Instruction = (
_instruction:
Expand Down Expand Up @@ -67,7 +70,7 @@ type ParsedVerifySecp256Instruction = {
};

export type ParsedSecp256Instruction = {
instructionType: Secp256Instruction.Verify;
instructionType: typeof Secp256Instruction.Verify;
} & ParsedVerifySecp256Instruction;
Comment thread
ulissesferreira marked this conversation as resolved.

export const parseVerifySecp256Instruction = (instruction: IInstruction) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ async function onConfirmButtonClick({ id }: { id: string }) {
await resolveInterface(id, true);
}

export enum ConfirmSignInFormNames {
Cancel = 'confirm-sign-in-cancel',
Confirm = 'confirm-sign-in-confirm',
}
export const ConfirmSignInFormNames = {
Cancel: 'confirm-sign-in-cancel',
Confirm: 'confirm-sign-in-confirm',
} as const;

export type ConfirmSignInFormNames =
(typeof ConfirmSignInFormNames)[keyof typeof ConfirmSignInFormNames];

export const eventHandlers = {
[ConfirmSignInFormNames.Cancel]: onCancelButtonClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ async function onConfirmButtonClick({ id }: { id: string }) {
await resolveInterface(id, true);
}

export enum ConfirmSignMessageFormNames {
Cancel = 'confirm-sign-message-cancel',
Confirm = 'confirm-sign-message-confirm',
}
export const ConfirmSignMessageFormNames = {
Cancel: 'confirm-sign-message-cancel',
Confirm: 'confirm-sign-message-confirm',
} as const;

export type ConfirmSignMessageFormNames =
(typeof ConfirmSignMessageFormNames)[keyof typeof ConfirmSignMessageFormNames];

export const eventHandlers = {
[ConfirmSignMessageFormNames.Cancel]: onCancelButtonClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ async function onConfirmButtonClick({ id }: { id: string }) {
);
}

export enum ConfirmSignAndSendTransactionFormNames {
ShowAdvanced = 'confirm-sign-and-send-transaction-show-advanced',
Cancel = 'confirm-sign-and-send-transaction-cancel',
Confirm = 'confirm-sign-and-send-transaction-confirm',
}
export const ConfirmSignAndSendTransactionFormNames = {
ShowAdvanced: 'confirm-sign-and-send-transaction-show-advanced',
Cancel: 'confirm-sign-and-send-transaction-cancel',
Confirm: 'confirm-sign-and-send-transaction-confirm',
} as const;

export type ConfirmSignAndSendTransactionFormNames =
(typeof ConfirmSignAndSendTransactionFormNames)[keyof typeof ConfirmSignAndSendTransactionFormNames];

export const eventHandlers = {
[ConfirmSignAndSendTransactionFormNames.ShowAdvanced]:
Expand Down
10 changes: 4 additions & 6 deletions packages/solana-wallet-snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,10 @@ export const onCronjob: OnCronjobHandler = async ({ request }) => {

if (!handler) {
throw new MethodNotFoundError(
`Cronjob / ScheduleBackgroundEvent method ${method} not found. Available methods: ${Object.values(
[
...Object.values(CronjobMethod),
...Object.values(ScheduleBackgroundEventMethod),
],
).toString()}`,
`Cronjob / ScheduleBackgroundEvent method ${String(method)} not found. Available methods: ${[
...Object.values(CronjobMethod),
...Object.values(ScheduleBackgroundEventMethod),
].join(',')}`,
) as unknown as Error;
}
return handler({ request });
Expand Down