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
27 changes: 27 additions & 0 deletions .yarn/patches/@noble-hashes-npm-1.7.1-4106ab26c5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/esm/cryptoNode.js b/esm/cryptoNode.js
index 4f77e8f46c5e242e1e3cb92712dc65e95a8b8eb0..acd05d884061e18adf27d33ba4a1c55e9cc85e7f 100644
--- a/esm/cryptoNode.js
+++ b/esm/cryptoNode.js
@@ -7,9 +7,19 @@
*/
// @ts-ignore
import * as nc from 'node:crypto';
-export const crypto = nc && typeof nc === 'object' && 'webcrypto' in nc
- ? nc.webcrypto
- : nc && typeof nc === 'object' && 'randomBytes' in nc
+// It seems `webpack` is not able to resolve `nc.webcrypto` at build time. Probably because
+// we use `crypto-browserify` under the hood, and this package does not expose `webcrypto`.
+// While this work when using `require` imports, it seems to fail with ESM exports (at least
+// in this case).
+// export const crypto = nc && typeof nc === 'object' && 'webcrypto' in nc
+// ? nc.webcrypto
+// : nc && typeof nc === 'object' && 'randomBytes' in nc
+// ? nc
+// : undefined;
+
+// We just fallback to the "normal crypto" object to workaround this.
+export const crypto =
+ nc && typeof nc === 'object' && 'randomBytes' in nc
? nc
: undefined;
//# sourceMappingURL=cryptoNode.js.map
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,10 @@
"packageManager": "yarn@3.6.3",
"engines": {
"node": ">=18.0.0"
},
"resolutions": {
"@noble/hashes@^1.1.2": "patch:@noble/hashes@npm%3A1.7.1#./.yarn/patches/@noble-hashes-npm-1.7.1-4106ab26c5.patch",
"@noble/hashes@^1.3.1": "patch:@noble/hashes@npm%3A1.7.1#./.yarn/patches/@noble-hashes-npm-1.7.1-4106ab26c5.patch",
"@noble/hashes@^1.3.2": "patch:@noble/hashes@npm%3A1.7.1#./.yarn/patches/@noble-hashes-npm-1.7.1-4106ab26c5.patch"
Comment on lines +62 to +64
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only add the resolutions for the packages that were causing the webpack build issue

}
}
3 changes: 2 additions & 1 deletion packages/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@metamask/keyring-api": "^8.1.3",
"@metamask/keyring-api": "^21.0.0",
"@metamask/keyring-snap-client": "^8.0.0",
"@metamask/providers": "^13.0.0",
"@mui/icons-material": "^5.14.0",
"@mui/material": "^5.14.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/site/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';
import { KeyringSnapRpcClient } from '@metamask/keyring-api';
import { KeyringSnapRpcClient } from '@metamask/keyring-snap-client';
import Grid from '@mui/material/Grid';
import React, { useCallback, useContext, useEffect, useState } from 'react';

Expand Down
3 changes: 2 additions & 1 deletion packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"@ethereumjs/tx": "^4.1.2",
"@ethereumjs/util": "^8.0.5",
"@metamask/eth-sig-util": "^7.0.1",
"@metamask/keyring-api": "^8.1.3",
"@metamask/keyring-api": "^21.0.0",
"@metamask/keyring-snap-sdk": "^7.0.0",
"@metamask/snaps-sdk": "^6.19.0",
"@metamask/utils": "^8.1.0",
"uuid": "^9.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "git+https://github.com/MetaMask/snap-simple-keyring.git"
},
"source": {
"shasum": "bFMN5hlkguPBHNaiusJPWZh6yhFnTShcY1mu0Ko5YMM=",
"shasum": "JqHSAfhSdIosNdTXR5Pi6lHdO9hTuRSyRE0Q0Tvzaks=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
MethodNotSupportedError,
handleKeyringRequest,
} from '@metamask/keyring-api';
} from '@metamask/keyring-snap-sdk';
import type {
OnKeyringRequestHandler,
OnRpcRequestHandler,
Expand Down
13 changes: 8 additions & 5 deletions packages/snap/src/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ import {
import type {
Keyring,
KeyringAccount,
KeyringEventPayload,
KeyringRequest,
SubmitRequestResponse,
} from '@metamask/keyring-api';
import {
EthAccountType,
EthMethod,
emitSnapKeyringEvent,
EthScope,
KeyringEvent,
} from '@metamask/keyring-api';
import { KeyringEvent } from '@metamask/keyring-api/dist/events';
import { emitSnapKeyringEvent } from '@metamask/keyring-snap-sdk';
import { type Json, type JsonRpcRequest } from '@metamask/utils';
import { Buffer } from 'buffer';
import { v4 as uuid } from 'uuid';
Expand Down Expand Up @@ -94,6 +96,7 @@ export class SimpleKeyring implements Keyring {
id: uuid(),
options,
address,
scopes: [EthScope.Eoa],
methods: [
EthMethod.PersonalSign,
EthMethod.Sign,
Expand Down Expand Up @@ -392,9 +395,9 @@ export class SimpleKeyring implements Keyring {
await saveState(this.#state);
}

async #emitEvent(
event: KeyringEvent,
data: Record<string, Json>,
async #emitEvent<Event extends KeyringEvent>(
event: Event,
data: KeyringEventPayload<Event>,
): Promise<void> {
await emitSnapKeyringEvent(snap, event, data);
}
Expand Down
Loading
Loading