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
2 changes: 1 addition & 1 deletion packages/bitcoin-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": "sYefpN30aR0fb7v2DtdJ+jNFSnJJX5jtqvdsDof4RHQ=",
"shasum": "DAuPn0nXZ23flLpbBbGrnOrZW6wYqw0MofHBQ9vjD5U=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
51 changes: 29 additions & 22 deletions packages/bitcoin-wallet-snap/src/entities/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,20 @@ export type BitcoinAccount = {
applyUnconfirmedTx(tx: Transaction, lastSeen: number): void;
};

export enum AccountCapability {
SignPsbt = 'signPsbt',
ComputeFee = 'computeFee',
FillPsbt = 'fillPsbt',
BroadcastPsbt = 'broadcastPsbt',
SendTransfer = 'sendTransfer',
GetUtxo = 'getUtxo',
ListUtxos = 'listUtxos',
PublicDescriptor = 'publicDescriptor',
SignMessage = 'signMessage',
}
export const AccountCapability = {
SignPsbt: 'signPsbt',
ComputeFee: 'computeFee',
FillPsbt: 'fillPsbt',
BroadcastPsbt: 'broadcastPsbt',
SendTransfer: 'sendTransfer',
GetUtxo: 'getUtxo',
ListUtxos: 'listUtxos',
PublicDescriptor: 'publicDescriptor',
SignMessage: 'signMessage',
} as const;

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

/**
* BitcoinAccountRepository is a repository that manages Bitcoin accounts.
Expand Down Expand Up @@ -332,18 +335,22 @@ export type BitcoinAccountRepository = {
getFrozenUTXOs(id: string): Promise<string[]>;
};

export enum Purpose {
Legacy = 44,
Segwit = 49,
NativeSegwit = 84,
Taproot = 86,
Multisig = 45,
}
export const Purpose = {
Legacy: 44,
Segwit: 49,
NativeSegwit: 84,
Taproot: 86,
Multisig: 45,
} as const;

export enum Slip44 {
Bitcoin = 0,
Testnet = 1,
}
export type Purpose = (typeof Purpose)[keyof typeof Purpose];

export const Slip44 = {
Bitcoin: 0,
Testnet: 1,
} as const;

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

export const addressTypeToPurpose: Record<AddressType, Purpose> = {
p2pkh: Purpose.Legacy,
Expand Down
11 changes: 7 additions & 4 deletions packages/bitcoin-wallet-snap/src/entities/confirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ export type SignPsbtConfirmationContext = {
inputCount: number;
};

export enum ConfirmationEvent {
Confirm = 'confirmation-confirm',
Cancel = 'confirmation-cancel',
}
export const ConfirmationEvent = {
Confirm: 'confirmation-confirm',
Cancel: 'confirmation-cancel',
} as const;

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

/**
* ConfirmationRepository is a repository that manages request confirmations for dApps.
Expand Down
16 changes: 9 additions & 7 deletions packages/bitcoin-wallet-snap/src/entities/currency.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { Network } from '@metamask/bitcoindevkit';

export enum CurrencyUnit {
Bitcoin = 'BTC',
Testnet = 'tBTC',
Signet = 'sBTC',
Regtest = 'rBTC',
Fiat = 'fiat', // Can also be cryptos like ETH, but will be fiat for 99% of users
}
export const CurrencyUnit = {
Bitcoin: 'BTC',
Testnet: 'tBTC',
Signet: 'sBTC',
Regtest: 'rBTC',
Fiat: 'fiat', // Can also be cryptos like ETH, but will be fiat for 99% of users
} as const;

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

export type CurrencyRate = {
conversionRate: number;
Expand Down
37 changes: 21 additions & 16 deletions packages/bitcoin-wallet-snap/src/entities/send-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ export type SendFormContext = {
locale: string;
};

export enum SendFormEvent {
Amount = 'amount',
Recipient = 'recipient',
ClearRecipient = 'clearRecipient',
ClearAmount = 'clearAmount',
Confirm = 'confirm',
Cancel = 'cancel',
Max = 'max',
Account = 'account',
Asset = 'asset',
SwitchCurrency = 'switchCurrency',
}
export const SendFormEvent = {
Amount: 'amount',
Recipient: 'recipient',
ClearRecipient: 'clearRecipient',
ClearAmount: 'clearAmount',
Confirm: 'confirm',
Cancel: 'cancel',
Max: 'max',
Account: 'account',
Asset: 'asset',
SwitchCurrency: 'switchCurrency',
} as const;

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

export type ReviewTransactionContext = {
from: string;
Expand All @@ -75,10 +77,13 @@ export type ReviewTransactionContext = {
sendForm?: SendFormContext;
};

export enum ReviewTransactionEvent {
Send = 'send',
HeaderBack = 'headerBack',
}
export const ReviewTransactionEvent = {
Send: 'send',
HeaderBack: 'headerBack',
} as const;

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

/**
* SendFlowRepository is a repository that manages Bitcoin Send flow interfaces.
Expand Down
15 changes: 9 additions & 6 deletions packages/bitcoin-wallet-snap/src/entities/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ export type SyncResult = {
transactionsToNotify: WalletTx[];
};

export enum TrackingSnapEvent {
TransactionFinalized = 'Transaction Finalized',
TransactionReceived = 'Transaction Received',
TransactionReorged = 'Transaction Reorged',
TransactionSubmitted = 'Transaction Submitted',
}
export const TrackingSnapEvent = {
TransactionFinalized: 'Transaction Finalized',
TransactionReceived: 'Transaction Received',
TransactionReorged: 'Transaction Reorged',
TransactionSubmitted: 'Transaction Submitted',
} as const;

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

/**
* The SnapClient represents the MetaMask Snap state and manages the BIP-32 entropy from the Wallet SRP.
Expand Down
14 changes: 8 additions & 6 deletions packages/bitcoin-wallet-snap/src/handlers/CronHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { InexistentMethodError, SynchronizationError } from '../entities';
import type { SnapClient, SyncResult } from '../entities';
import type { SendFlowUseCases, AccountUseCases } from '../use-cases';

export enum CronMethod {
SynchronizeAccounts = 'synchronizeAccounts',
RefreshRates = 'refreshRates',
SyncSelectedAccounts = 'syncSelectedAccounts',
FullScanAccount = 'fullScanAccount',
}
export const CronMethod = {
SynchronizeAccounts: 'synchronizeAccounts',
RefreshRates: 'refreshRates',
SyncSelectedAccounts: 'syncSelectedAccounts',
FullScanAccount: 'fullScanAccount',
} as const;

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

export const SendFormRefreshRatesRequest = object({
interfaceId: string(),
Expand Down
16 changes: 9 additions & 7 deletions packages/bitcoin-wallet-snap/src/handlers/caip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ export const networkToScope = reverseMapping(scopeToNetwork);

export const addressTypeToCaip = reverseMapping(caipToAddressType);

export enum Caip19Asset {
Bitcoin = 'bip122:000000000019d6689c085ae165831e93/slip44:0',
Testnet = 'bip122:000000000933ea01ad0ee984209779ba/slip44:0',
Testnet4 = 'bip122:00000000da84f2bafbbc53dee25a72ae/slip44:0',
Signet = 'bip122:00000008819873e925422c1ff0f99f7c/slip44:0',
Regtest = 'bip122:regtest/slip44:0',
}
export const Caip19Asset = {
Bitcoin: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
Testnet: 'bip122:000000000933ea01ad0ee984209779ba/slip44:0',
Testnet4: 'bip122:00000000da84f2bafbbc53dee25a72ae/slip44:0',
Signet: 'bip122:00000008819873e925422c1ff0f99f7c/slip44:0',
Regtest: 'bip122:regtest/slip44:0',
} as const;

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

export const NetworkStruct = enums(Object.values(BtcScope));

Expand Down
42 changes: 23 additions & 19 deletions packages/bitcoin-wallet-snap/src/handlers/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,29 @@ import {
import type { BitcoinAccount, CodifiedError, Logger } from '../entities';
import { ValidationError } from '../entities';

export enum RpcMethod {
StartSendTransactionFlow = 'startSendTransactionFlow',
SignAndSendTransaction = 'signAndSendTransaction',
ComputeFee = 'computeFee',
VerifyMessage = 'verifyMessage',
OnAddressInput = 'onAddressInput',
OnAmountInput = 'onAmountInput',
ConfirmSend = 'confirmSend',
SignRewardsMessage = 'signRewardsMessage',
SignProofOfOwnership = 'signProofOfOwnership',
}

export enum SendErrorCodes {
// eslint-disable-next-line @typescript-eslint/no-shadow
Required = 'Required',
Invalid = 'Invalid',
InsufficientBalance = 'InsufficientBalance',
InsufficientBalanceToCoverFee = 'InsufficientBalanceToCoverFee',
}
export const RpcMethod = {
StartSendTransactionFlow: 'startSendTransactionFlow',
SignAndSendTransaction: 'signAndSendTransaction',
ComputeFee: 'computeFee',
VerifyMessage: 'verifyMessage',
OnAddressInput: 'onAddressInput',
OnAmountInput: 'onAmountInput',
ConfirmSend: 'confirmSend',
SignRewardsMessage: 'signRewardsMessage',
SignProofOfOwnership: 'signProofOfOwnership',
} as const;

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

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

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

export const NonEmptyStringStruct = refine(
nonempty(string()),
Expand Down