Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/stellar-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": "XmHWNIVVLlhvKq+iksu3PyMYqx95Zj7lQAB/s1cOFlk=",
"shasum": "caN9ku7+kU6FA935tMmSPElKb+qOqHvnG/drqSdfMv0=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
18 changes: 10 additions & 8 deletions packages/stellar-wallet-snap/src/api/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import { KnownCaip2ChainId } from './network';

/** Stellar Asset namespace */
/** Please see https://namespaces.chainagnostic.org/stellar/caip19#asset-namespaces */
export enum AssetType {
Native = 'slip44',
Token = 'asset',
Sep41 = 'sep41',
}
export const AssetType = {
Native: 'slip44',
Token: 'asset',
Sep41: 'sep41',
} as const;

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

/** Known CAIP-19 IDs */
export const KnownCaip19Slip44IdStruct =
definePattern<`${KnownCaip2ChainId}/${AssetType.Native}:${typeof STELLAR_COIN_TYPE}`>(
definePattern<`${KnownCaip2ChainId}/${typeof AssetType.Native}:${typeof STELLAR_COIN_TYPE}`>(
'KnownCaip19Slip44Id',
/^stellar:(?:pubnet|testnet)\/slip44:148$/u,
);
Expand All @@ -35,13 +37,13 @@ export const KnownCaip19Slip44IdMap: Record<
* @see https://namespaces.chainagnostic.org/stellar/caip19#asset-namespaces
*/
export const KnownCaip19ClassicAssetStruct =
definePattern<`${KnownCaip2ChainId}/${AssetType.Token}:${string}-${string}`>(
definePattern<`${KnownCaip2ChainId}/${typeof AssetType.Token}:${string}-${string}`>(
'KnownCaip19ClassicAsset',
/^stellar:(?:pubnet|testnet)\/asset:[A-Za-z0-9]{1,12}-G[A-Z2-7]{55}$/u,
);

export const KnownCaip19Sep41AssetStruct =
definePattern<`${KnownCaip2ChainId}/${AssetType.Sep41}:${string}`>(
definePattern<`${KnownCaip2ChainId}/${typeof AssetType.Sep41}:${string}`>(
'KnownCaip19Sep41Asset',
/^stellar:(?:pubnet|testnet)\/sep41:C[A-Z2-7]{55}$/u,
);
Expand Down
12 changes: 7 additions & 5 deletions packages/stellar-wallet-snap/src/api/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export enum Environment {
Local = 'local',
Test = 'test',
Production = 'production',
}
export const Environment = {
Local: 'local',
Test: 'test',
Production: 'production',
} as const;

export type Environment = (typeof Environment)[keyof typeof Environment];
11 changes: 7 additions & 4 deletions packages/stellar-wallet-snap/src/api/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { KnownCaipNamespace } from '@metamask/utils';

/** Known CAIP-2 IDs */
/** Please see https://namespaces.chainagnostic.org/stellar/caip2 */
export enum KnownCaip2ChainId {
Mainnet = `${KnownCaipNamespace.Stellar}:pubnet`,
Testnet = `${KnownCaipNamespace.Stellar}:testnet`,
}
export const KnownCaip2ChainId = {
Mainnet: `${KnownCaipNamespace.Stellar}:pubnet`,
Testnet: `${KnownCaipNamespace.Stellar}:testnet`,
} as const;

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

export const KnownCaip2ChainIdStruct = enums(Object.values(KnownCaip2ChainId));
11 changes: 7 additions & 4 deletions packages/stellar-wallet-snap/src/handlers/accountResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import { OnChainAccount } from '../services/on-chain-account';
import type { WalletService } from '../services/wallet';
import { Wallet } from '../services/wallet';

export enum ResolveAccountSource {
OnChain = 'on-chain',
State = 'state',
}
export const ResolveAccountSource = {
OnChain: 'on-chain',
State: 'state',
} as const;

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

export type ResolveAccountOptions = {
/** Whether to load the activated on-chain account. */
Expand Down
46 changes: 27 additions & 19 deletions packages/stellar-wallet-snap/src/handlers/clientRequest/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,41 @@ import { isSep41Id } from '../../utils';
/**
* Enum for the client request method.
*/
export enum ClientRequestMethod {
export const ClientRequestMethod = {
/** -------------------------------- Wallet Standard -------------------------------- */
OnAddressInput = 'onAddressInput',
OnAmountInput = 'onAmountInput',
ConfirmSend = 'confirmSend',
OnAddressInput: 'onAddressInput',
OnAmountInput: 'onAmountInput',
ConfirmSend: 'confirmSend',
// Standard multichain workflow for bridge
SignAndSendTransaction = 'signAndSendTransaction',
ComputeFee = 'computeFee',
SignAndSendTransaction: 'signAndSendTransaction',
ComputeFee: 'computeFee',
/** -------------------------------- Stellar Specific -------------------------------- */
ChangeTrustOpt = 'changeTrustOpt',
}
ChangeTrustOpt: 'changeTrustOpt',
} as const;

export enum MultiChainSendErrorCodes {
// eslint-disable-next-line @typescript-eslint/no-shadow
Required = 'Required',
Invalid = 'Invalid',
InsufficientBalance = 'InsufficientBalance',
InsufficientBalanceToCoverFee = 'InsufficientBalanceToCoverFee',
}
export type ClientRequestMethod =
(typeof ClientRequestMethod)[keyof typeof ClientRequestMethod];

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

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

/**
* Trustline change intent for {@link ClientRequestMethod.ChangeTrustOpt}.
*/
export enum ChangeTrustOptAction {
Add = 'add',
Delete = 'delete',
}
export const ChangeTrustOptAction = {
Add: 'add',
Delete: 'delete',
} as const;

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

/**
* Validation struct for the client request method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ export class ChangeTrustOptHandler extends BaseClientRequestHandler<
fee: string;
transaction: Transaction;
confirmationInterfaceKey:
| ConfirmationInterfaceKey.ChangeTrustlineOptIn
| ConfirmationInterfaceKey.ChangeTrustlineOptOut;
| typeof ConfirmationInterfaceKey.ChangeTrustlineOptIn
| typeof ConfirmationInterfaceKey.ChangeTrustlineOptOut;
}): Promise<boolean> {
const {
request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('OnAmountInputHandler', () => {
});

it('resolves on-chain account using scope derived from assetId', async () => {
const testnetAssetId = `${KnownCaip2ChainId.Testnet}/slip44:148`;
const testnetAssetId = `${KnownCaip2ChainId.Testnet}/slip44:148` as const;
const {
handler,
account,
Expand Down
15 changes: 9 additions & 6 deletions packages/stellar-wallet-snap/src/handlers/cronjob/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ export type ICronjobRequestHandler = {
handle: (request: JsonRpcRequest) => Promise<Json>;
};

export enum BackgroundEventMethod {
SynchronizeAssets = 'synchronizeAssets',
SynchronizeAccounts = 'synchronizeAccounts',
TrackTransaction = 'trackTransaction',
RefreshConfirmationContext = 'refreshConfirmationContext',
}
export const BackgroundEventMethod = {
SynchronizeAssets: 'synchronizeAssets',
SynchronizeAccounts: 'synchronizeAccounts',
TrackTransaction: 'trackTransaction',
RefreshConfirmationContext: 'refreshConfirmationContext',
} as const;

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

export const BackgroundEventMethodStruct = enums(
Object.values(BackgroundEventMethod),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import type { Json } from '@metamask/utils';
import type { ContextWithPrices } from '../../../ui/confirmation/api';

/** Identifies which confirmation context refreshers to run for a cron cycle. */
export enum ConfirmationContextRefresherKey {
Prices = 'prices',
Scan = 'scan',
Transaction = 'transaction',
}
export const ConfirmationContextRefresherKey = {
Prices: 'prices',
Scan: 'scan',
Transaction: 'transaction',
} as const;

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

export const ConfirmationContextRefresherKeyStruct = enums(
Object.values(ConfirmationContextRefresherKey),
Expand Down
13 changes: 8 additions & 5 deletions packages/stellar-wallet-snap/src/handlers/keyring/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ import { HashIdPreimageXdrStruct, XdrStruct } from '../../api/xdr';
import { networkToCaip2ChainId } from '../../services/network/utils';

/** JSON-RPC methods supported by this snap's multichain keyring. */
export enum MultichainMethod {
SignMessage = 'signMessage',
SignTransaction = 'signTransaction',
SignAuthEntry = 'signAuthEntry',
}
export const MultichainMethod = {
SignMessage: 'signMessage',
SignTransaction: 'signTransaction',
SignAuthEntry: 'signAuthEntry',
} as const;

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

/** Superstruct validator for {@link MultichainMethod} string values. */
export const MultichainMethodStruct = enums(Object.values(MultichainMethod));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ export class KeyringException extends StellarSnapException {}
*
* @see https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0043.md
*/
export enum Sep43ErrorCode {
export const Sep43ErrorCode = {
/** Internal wallet error (JS runtime, programmer error, etc.). */
Internal = -1,
Internal: -1,
/** External service (Horizon, RPC, …) returned an error. */
ExternalService = -2,
ExternalService: -2,
/** Client app request is invalid (bad params, malformed XDR, unsupported option). */
InvalidRequest = -3,
InvalidRequest: -3,
/** User declined the confirmation. */
UserRejected = -4,
}
UserRejected: -4,
} as const;

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

/**
* Generic SEP-43 message that's user-safe to forward to the dapp.
Expand Down
11 changes: 7 additions & 4 deletions packages/stellar-wallet-snap/src/services/network/MultiCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ export const SIMULATION_ACCOUNT: string =
* it is recommended by Stellar official site.
* @see https://developers.stellar.org/docs/tools/sdks/contract-sdks#stellar-multicall--router-sdk
*/
export enum StellarRouterContract {
V0 = 'CBZV3HBP672BV7FF3ZILVT4CNPW3N5V2WTJ2LAGOAYW5R7L2D5SLUDFZ',
V1 = 'CCM23MFAJHDWUMF3IM3UPUI4ZUFFKX6OWJNJRUKO2W6MUTQNQWWFH7DC',
}
export const StellarRouterContract = {
V0: 'CBZV3HBP672BV7FF3ZILVT4CNPW3N5V2WTJ2LAGOAYW5R7L2D5SLUDFZ',
V1: 'CCM23MFAJHDWUMF3IM3UPUI4ZUFFKX6OWJNJRUKO2W6MUTQNQWWFH7DC',
} as const;

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

export type StellarRouterParams = {
rpcClient: rpc.Server;
Expand Down
28 changes: 15 additions & 13 deletions packages/stellar-wallet-snap/src/services/network/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import type { KnownCaip19AssetId } from '../../api';
*
* @see https://developers.stellar.org/docs/data/apis/horizon/api-reference/errors/result-codes/transactions
*/
export enum KnownRpcError {
TxBadSeq = 'txBadSeq',
TxBadAuth = 'txBadAuth',
TxTooEarly = 'txTooEarly',
TxTooLate = 'txTooLate',
TxInsufficientFee = 'txInsufficientFee',
TxInsufficientBalance = 'txInsufficientBalance',
TxInsufficientReserve = 'txInsufficientReserve',
TxFailed = 'txFailed',
TxMissingOperation = 'txMissingOperation',
TxInternalError = 'txInternalError',
TxBadAuthExtra = 'txBadAuthExtra',
}
export const KnownRpcError = {
TxBadSeq: 'txBadSeq',
TxBadAuth: 'txBadAuth',
TxTooEarly: 'txTooEarly',
TxTooLate: 'txTooLate',
TxInsufficientFee: 'txInsufficientFee',
TxInsufficientBalance: 'txInsufficientBalance',
TxInsufficientReserve: 'txInsufficientReserve',
TxFailed: 'txFailed',
TxMissingOperation: 'txMissingOperation',
TxInternalError: 'txInternalError',
TxBadAuthExtra: 'txBadAuthExtra',
} as const;

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

/**
* Asset data for a Stellar classic asset.
Expand Down
54 changes: 33 additions & 21 deletions packages/stellar-wallet-snap/src/services/transaction-scan/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,45 @@ import { KnownCaip2ChainId, XdrStruct } from '../../api';
*
* @see packages/snap/src/ui/confirmation/components/TransactionAlert.tsx
*/
export enum TransactionScanErrorId {
InsufficientBalance = 'insufficientbalance',
InsufficientFunds = 'insufficientfunds',
InvalidTransaction = 'invalidtransaction',
InvalidAddress = 'invalidaddress',
NoTrustline = 'notrustline',
TransactionExpired = 'transactionexpired',
}
export const TransactionScanErrorId = {
InsufficientBalance: 'insufficientbalance',
InsufficientFunds: 'insufficientfunds',
InvalidTransaction: 'invalidtransaction',
InvalidAddress: 'invalidaddress',
NoTrustline: 'notrustline',
TransactionExpired: 'transactionexpired',
} as const;

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

/** TransactionScanOption - Options for the transaction scan. */
export enum TransactionScanOption {
Simulation = 'simulation',
Validation = 'validation',
}
export const TransactionScanOption = {
Simulation: 'simulation',
Validation: 'validation',
} as const;

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

/** TransactionScanValidationType */
export enum TransactionScanValidationType {
Benign = 'Benign',
Warning = 'Warning',
Malicious = 'Malicious',
}
export const TransactionScanValidationType = {
Benign: 'Benign',
Warning: 'Warning',
Malicious: 'Malicious',
} as const;

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

/** AssetChangeDirection - Direction of an estimated balance change relative to the signer. */
export enum AssetChangeDirection {
In = 'in',
Out = 'out',
}
export const AssetChangeDirection = {
In: 'in',
Out: 'out',
} as const;

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

/** Security Alerts API chain identifier. */
export type SecurityAlertsChain = 'pubnet' | 'testnet' | 'futurenet';
Expand Down
Loading
Loading