Skip to content

Conversation

deuszx
Copy link
Contributor

@deuszx deuszx commented May 28, 2025

Updates the examples (and extension) to use the latest API from linera-protocol/linera-web.

A new example integration - called hosted-counter-metamask - was added which uses MetamaskSigner.

Faucet URL and app IDs are now provided via env variables (see .env file).

Closes #51

Below the recording of integration w/ MetaMask

Screen.Recording.2025-06-11.at.17.48.02.mov

@deuszx deuszx force-pushed the embedded-js-signer branch from 7d2a4db to acd76ad Compare May 28, 2025 12:38
@deuszx deuszx changed the title Add basic EmbeddedEIP191Signer Update examples to use latest linera-web APIs. May 30, 2025
@deuszx deuszx force-pushed the embedded-js-signer branch from 68a4cb8 to 3d9516f Compare May 30, 2025 15:03
@deuszx deuszx force-pushed the embedded-js-signer branch from a21648e to f236412 Compare June 3, 2025 10:10
@deuszx deuszx requested a review from Twey June 3, 2025 14:20
@deuszx deuszx marked this pull request as ready for review June 3, 2025 14:20
github-merge-queue bot pushed a commit to linera-io/linera-protocol that referenced this pull request Jun 9, 2025
## Motivation

There's some cleanup work being done in
linera-io/linera-web#49 that's incompatible with
current configuration and yields `Uncaught ReferenceError: require is
not defined` error.

## Proposal

Update the compilation options to more modern ones that fix the error.

## Test Plan

CI

## Release Plan

- Nothing to do 

## Links

- [reviewer
checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
@deuszx deuszx force-pushed the embedded-js-signer branch from c20b927 to 39c57b5 Compare June 9, 2025 10:59
@deuszx deuszx force-pushed the embedded-js-signer branch from a5a32e3 to 93f5409 Compare June 12, 2025 17:22
@deuszx deuszx force-pushed the embedded-js-signer branch from 4f04b2d to ad24510 Compare June 14, 2025 11:02

<script type="module">
import * as linera from '@linera/client';
import { PrivateKey } from '@linera/signer';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I think it would be better to use this qualified as signer.PrivateKey. Otherwise it's not necessarily clear to the reader that this is a private-key signer and not just a private key.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(I guess it was imported unqualified because the module name used to be suffixed to the class name as well, but that's no longer the case)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought signer.PrivateKey is unnecessary and files are small enough to easily see where the import comes from.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I guess it was imported unqualified because the module name used to be suffixed to the class name as well, but that's no longer the case)

Exactly :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I kind of agree, which is why it's a nit, but for people encountering this API for the first time it might be best to be super explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's why I wanted to call this PrivateKeySigner - to avoid confusion like this :)

Copy link
Collaborator

@Twey Twey Jun 23, 2025

Choose a reason for hiding this comment

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

I've written this before but — the reason modules are nice to have as a language construct is that the information that is obvious about a name changes depending on the context. Back in the good old days of C we would always have to write struct linera_signer_private_key everywhere because there weren't any kind of modules to put things in. That's usually sufficiently informative, but in a lot of cases you want to do something a bit different:

  • inside the Linera codebase (or a Linera-specific module in an external codebase) it's pretty obvious that you're talking about Linera things, so calling it a ‘Linera private key signer’ (LineraPrivateKeySigner) isn't necessary, and it's enough to refer to it as a ‘private key signer’ (signer.PrivateKey);
  • inside a ‘signer’ module (e.g. abstraction layer) of some external project it might not be obvious that this thing is specific to Linera but it is obvious that it's a signer, so you want to refer to it as a ‘Linera private key’ (linera.PrivateKey);
  • inside a ‘Linera signer’ module there's no need for any of this information (everything here is a Linera signer, or helpers for one) and the only thing you care about is that it is a private key signer (PrivateKey);
  • bit of a contrived example for this one in particular (because ‘private key’ is jargon usually specific to crypto), but inside a very high-level context about generic authentication mechanisms you might have a mechanism that's about actual physical signatures made with a pen on paper! So you might want to disambiguate that by referring to this as the Linera crypto signer (signer.crypto.linera.PrivateKey).

When you try to include all possible context into the base name, you're cursing your users to always include all of that context, even when it's not relevant, and to not be able to decide (or at least be strongly discouraged from deciding) what information is relevant to them. Conversely, you're taking on the burden of trying to guess all the possible contexts that the name could appear in and creating a name that's suitably unambiguous in every single one. Using the language's module facilities, on the other hand, means consumers (including you, the producer!) can adapt the name in different contexts to omit the information that's obvious and keep or add information that's pertinent.

The fact that the word ‘signer’ is pertinent in this context doesn't mean it's pertinent in all contexts such that it should be made part of the core name. In fact, a great example of a context in which it's not pertinent at all (because it's super obvious) is the module where it's defined, linera_base::crypto::signer.

@deuszx deuszx merged commit 9cb72b3 into main Jun 25, 2025
1 check passed
@deuszx deuszx deleted the embedded-js-signer branch June 27, 2025 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Examples to use latest Signer abstraction from linera-protocol
2 participants