Skip to content

Commit 5028a44

Browse files
authored
TypeScript signers cleanups. (#4103)
## Motivation In various places some misc needs came up: - rename `MetaMaskEIP191Signer` to simply `MetaMask` - rename `PrivateKeySigner` to `PrivateKey` (signer is silent) - when built, `@metamask/utils` throws errors about invalid symbols - this is fixed by `skipLibraryCheck: true` in `tsconfig.build.json` - the problem does not show up in the runtime ## Proposal Do all of that. ## Test Plan Manual ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist) --------- Signed-off-by: deuszx <[email protected]>
1 parent ad9e038 commit 5028a44

File tree

6 files changed

+84
-26
lines changed

6 files changed

+84
-26
lines changed

linera-web/signer/package-lock.json

Lines changed: 55 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

linera-web/signer/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
},
1616
"dependencies": {
1717
"@linera/client": "file:../",
18-
"ethers": "^6.14.3",
19-
"@metamask/providers": "^22.1.0"
18+
"@metamask/providers": "^22.1.0",
19+
"ethers": "^6.14.3"
2020
},
2121
"keywords": [],
2222
"author": "Linera <[email protected]>",
2323
"license": "Apache-2.0",
2424
"homepage": "https://github.com/linera-io/linera-protocol/linera-web/signer/#readme",
2525
"devDependencies": {
2626
"@types/jest": "^29.5.14",
27+
"@types/node": "^24.0.1",
2728
"@types/readable-stream": "^4.0.21",
2829
"jest": "^29.7.0",
2930
"ts-jest": "^29.3.4",

linera-web/signer/src/metamask.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,24 @@ declare global {
99
}
1010
}
1111

12-
export class MetaMaskEIP191Signer implements Signer {
12+
/**
13+
* A signer implementation that uses the MetaMask browser extension for signing.
14+
*
15+
* This class relies on the global `window.ethereum` object injected by MetaMask
16+
* and interacts with it using EIP-191-compliant requests. It provides a secure
17+
* mechanism for message signing through the user's MetaMask wallet.
18+
*
19+
* ⚠️ WARNING: This signer requires MetaMask to be installed and unlocked in the browser.
20+
* It will throw errors if MetaMask is unavailable, the user rejects a request, or
21+
* if the requested signer is not among the connected accounts.
22+
*
23+
* The `MetaMask` signer verifies that the connected account matches the specified
24+
* owner address before signing a message. All messages are encoded as hexadecimal
25+
* strings and signed using the `personal_sign` method.
26+
*
27+
* Suitable for production use where MetaMask is the expected signer interface.
28+
*/
29+
export class MetaMask implements Signer {
1330
private provider: ethers.BrowserProvider;
1431

1532
constructor() {

linera-web/signer/src/private-key.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ import { Signer } from "@linera/client";
1414
*
1515
* Supports key creation from both a raw private key and a mnemonic phrase.
1616
*/
17-
export class PrivateKeySigner implements Signer {
17+
export class PrivateKey implements Signer {
1818
private wallet: Wallet;
1919

2020
constructor(privateKeyHex: string) {
2121
this.wallet = new Wallet(privateKeyHex);
2222
}
2323

24-
static fromMnemonic(mnemonic: string): PrivateKeySigner {
24+
static fromMnemonic(mnemonic: string): PrivateKey {
2525
const wallet = ethers.Wallet.fromPhrase(mnemonic);
26-
return new PrivateKeySigner(wallet.privateKey);
26+
return new PrivateKey(wallet.privateKey);
2727
}
2828

2929
public address(): string {

linera-web/signer/tests/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ethers } from "ethers";
2-
import { PrivateKeySigner } from "../src";
2+
import { PrivateKey } from "../src";
33

44
test("constructs signer from mnemonic correctly", async () => {
55
const phrase = "test test test test test test test test test test test junk";
66

7-
const signer = PrivateKeySigner.fromMnemonic(phrase);
7+
const signer = PrivateKey.fromMnemonic(phrase);
88
const expectedWallet = ethers.Wallet.fromPhrase(phrase);
99

1010
// In Linera EIP-191 compatible wallet, the owner is the wallet address.
@@ -18,7 +18,7 @@ test("constructs signer from mnemonic correctly", async () => {
1818
test("signs message correctly", async () => {
1919
const secretKey =
2020
"f77a21701522a03b01c111ad2d2cdaf2b8403b47507ee0aec3c2e52b765d7a66";
21-
const signer = new PrivateKeySigner(secretKey);
21+
const signer = new PrivateKey(secretKey);
2222
const cryptoHash =
2323
"c520e2b24b05e70c39c36d4aa98e9129ac0079ea002d4c382e6996ea11946d1e";
2424
const owner = signer.address().toLowerCase();

linera-web/signer/tsconfig.build.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"noEmit": false,
66
"declaration": true,
77
"declarationMap": true,
8-
"emitDeclarationOnly": false
8+
"emitDeclarationOnly": false,
9+
"skipLibCheck": true
910
},
1011
"exclude": ["tests", "*/*.test.ts"]
1112
}

0 commit comments

Comments
 (0)