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
4 changes: 4 additions & 0 deletions packages/bitcoin-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix `onKeyringRequest` responses to return `Json` directly (v2 protocol) instead of the v1 `{ pending: false, result }` envelope ([#100](https://github.com/MetaMask/internal-snaps/pull/100))

## [2.0.0]

### Added
Expand Down
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": "ye8FAG8Punj6snX/zr6AwKJCidDHdim1FUHqKwjTQog=",
"shasum": "nmBUkNRCyH60zI0wMFb9HzlW6ZVjCRxnLZdWOKcp88s=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
import { Address } from '@metamask/bitcoindevkit';
import type {
KeyringAccount,
KeyringResponse,
Transaction as KeyringTransaction,
KeyringRequest,
} from '@metamask/keyring-api';
Expand Down Expand Up @@ -962,7 +961,7 @@ describe('KeyringHandler', () => {
describe('submitRequest', () => {
it('calls KeyringRequestHandler', async () => {
const mockRequest = mock<KeyringRequest>();
const expectedResponse = mock<KeyringResponse>();
const expectedResponse = { signature: 'mockSig' };
mockKeyringRequest.route.mockResolvedValue(expectedResponse);

const result = await handler.submitRequest(mockRequest);
Expand Down
5 changes: 2 additions & 3 deletions packages/bitcoin-wallet-snap/src/handlers/KeyringHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
CreateAccountOptions,
KeyringAccount,
KeyringRequest,
KeyringResponse,
Paginated,
Pagination,
ResolvedAccountAddress,
Expand All @@ -24,7 +23,7 @@ import type {
KeyringSnapRpc,
} from '@metamask/keyring-api/v2';
import { SnapError } from '@metamask/snaps-sdk';
import type { CaipChainId, JsonRpcRequest } from '@metamask/snaps-sdk';
import type { CaipChainId, Json, JsonRpcRequest } from '@metamask/snaps-sdk';
import { sensitive } from '@metamask/superstruct';
import { assert, is, string } from 'superstruct';
import { encode } from 'wif';
Expand Down Expand Up @@ -337,7 +336,7 @@ export class KeyringHandler implements KeyringSnapRpc {
};
}

async submitRequest(request: KeyringRequest): Promise<KeyringResponse> {
async submitRequest(request: KeyringRequest): Promise<Json> {
return this.#keyringRequest.route(request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,9 @@ describe('KeyringRequestHandler', () => {
3,
);
expect(result).toStrictEqual({
pending: false,
result: {
psbt: 'psbtBase64',
txid: 'txid',
canBeMalleable: false,
},
psbt: 'psbtBase64',
txid: 'txid',
canBeMalleable: false,
});
});

Expand All @@ -183,10 +180,7 @@ describe('KeyringRequestHandler', () => {

const result = await handler.route(noBroadcastRequest);

expect(result).toStrictEqual({
pending: false,
result: { psbt: 'psbtBase64', txid: null },
});
expect(result).toStrictEqual({ psbt: 'psbtBase64', txid: null });
});

it('throws AssertionError if usecase returns txid without canBeMalleable', async () => {
Expand Down Expand Up @@ -215,12 +209,9 @@ describe('KeyringRequestHandler', () => {
const result = await handler.route(mockRequest);

expect(result).toStrictEqual({
pending: false,
result: {
psbt: 'psbtBase64',
txid: 'txid',
canBeMalleable: true,
},
psbt: 'psbtBase64',
txid: 'txid',
canBeMalleable: true,
});
});

Expand Down Expand Up @@ -303,10 +294,7 @@ describe('KeyringRequestHandler', () => {

const result = await handler.route(mockRequest);

expect(result).toStrictEqual({
pending: false,
result: { psbt: 'psbtBase64', txid: null },
});
expect(result).toStrictEqual({ psbt: 'psbtBase64', txid: null });
});

it('does not sign if user cancels confirmation', async () => {
Expand Down Expand Up @@ -409,10 +397,7 @@ describe('KeyringRequestHandler', () => {
mockPsbt,
3,
);
expect(result).toStrictEqual({
pending: false,
result: { fee: '1000' },
});
expect(result).toStrictEqual({ fee: '1000' });
});

it('propagates errors from parsePsbt', async () => {
Expand Down Expand Up @@ -474,10 +459,7 @@ describe('KeyringRequestHandler', () => {
mockPsbt,
3,
);
expect(result).toStrictEqual({
pending: false,
result: { psbt: 'filledPsbtBase64' },
});
expect(result).toStrictEqual({ psbt: 'filledPsbtBase64' });
});

it('propagates errors from parsePsbt', async () => {
Expand Down Expand Up @@ -543,10 +525,7 @@ describe('KeyringRequestHandler', () => {
mockPsbt,
origin,
);
expect(result).toStrictEqual({
pending: false,
result: { txid: 'txid', canBeMalleable: false },
});
expect(result).toStrictEqual({ txid: 'txid', canBeMalleable: false });
});

it('passes canBeMalleable=true through for legacy P2PKH accounts', async () => {
Expand All @@ -560,10 +539,7 @@ describe('KeyringRequestHandler', () => {

const result = await handler.route(mockRequest);

expect(result).toStrictEqual({
pending: false,
result: { txid: 'txid', canBeMalleable: true },
});
expect(result).toStrictEqual({ txid: 'txid', canBeMalleable: true });
});

it('propagates errors from parsePsbt', async () => {
Expand Down Expand Up @@ -636,10 +612,7 @@ describe('KeyringRequestHandler', () => {
origin,
3,
);
expect(result).toStrictEqual({
pending: false,
result: { txid: 'txid', canBeMalleable: false },
});
expect(result).toStrictEqual({ txid: 'txid', canBeMalleable: false });
});

it('passes canBeMalleable=true through for legacy P2PKH accounts', async () => {
Expand All @@ -653,10 +626,7 @@ describe('KeyringRequestHandler', () => {

const result = await handler.route(mockRequest);

expect(result).toStrictEqual({
pending: false,
result: { txid: 'txid', canBeMalleable: true },
});
expect(result).toStrictEqual({ txid: 'txid', canBeMalleable: true });
});

it('propagates errors from sendTransfer', async () => {
Expand Down Expand Up @@ -704,10 +674,7 @@ describe('KeyringRequestHandler', () => {
GetUtxoRequest,
);
expect(mockAccountsUseCases.get).toHaveBeenCalledWith('account-id');
expect(result).toStrictEqual({
pending: false,
result: expectedUtxo,
});
expect(result).toStrictEqual(expectedUtxo);
});

it('throws NotFoundError when UTXO does not exist', async () => {
Expand Down Expand Up @@ -750,10 +717,7 @@ describe('KeyringRequestHandler', () => {
const result = await handler.route(mockRequest);

expect(mockAccountsUseCases.get).toHaveBeenCalledWith('account-id');
expect(result).toStrictEqual({
pending: false,
result: [mockUtxo, mockUtxo],
});
expect(result).toStrictEqual([mockUtxo, mockUtxo]);
});
});

Expand All @@ -774,10 +738,7 @@ describe('KeyringRequestHandler', () => {
const result = await handler.route(mockRequest);

expect(mockAccountsUseCases.get).toHaveBeenCalledWith('account-id');
expect(result).toStrictEqual({
pending: false,
result: 'publicDescriptor',
});
expect(result).toBe('publicDescriptor');
});
});

Expand All @@ -803,10 +764,7 @@ describe('KeyringRequestHandler', () => {
'message',
'metamask',
);
expect(result).toStrictEqual({
pending: false,
result: { signature: 'signature' },
});
expect(result).toStrictEqual({ signature: 'signature' });
});
});
});
Loading
Loading