Skip to content

Commit 8ca10f5

Browse files
authored
@linera/client: integrate signer (#4711)
## Motivation It's currently difficult to test the `@linera/client` package in isolation because it always requires a `Signer` instance to use, the most straightforward one of which is the `PrivateKey` signer that lives in `@linera/signer`. ## Proposal Integrate the private-key signer into the `@linera/client` package next to the `Signer` interface itself as `linera.PrivateKeySigner`. While we're breaking the API, fix up the package structure of `@linera/client` a bit (giving us a barrel file as a cleaner place to inject TypeScript code to live next to the Wasm and its generated shim), and remove some vestigial functions (`Signer.get_public_key()`, which is never used any more, and `Client.frontend()`, which made more sense when this library was intended to be the direct implementation of a Web extension). Since the erstwhile `@linera/signer` package now only contains the MetaMask signer, rename it to `@linera/metamask` and open up its scope to other MetaMask-specific signers and integrations. ## Test Plan Automated tests forthcoming :) but I've at least tried it manually with our counter and native-fungible examples. ## Release Plan - Nothing to do / These changes follow the usual release cycle. Breaks SDK API but no need to backport. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent a78abb6 commit 8ca10f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3775
-895
lines changed

.github/workflows/web.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
- name: Test the npm packages
8686
run: |
8787
cd web
88-
pnpm install
88+
pnpm install --frozen-lockfile
8989
pnpm -r run ci
9090
- name: Test `linera-views` on the Web
9191
run: |

examples/counter/index.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,27 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting chain…</code>
5151
<script type="importmap">
5252
{
5353
"imports": {
54-
"@linera/client": "./js/@linera/client/linera_web.js",
55-
"@linera/signer": "./js/@linera/signer/index.js"
54+
"@linera/client": "./js/@linera/client/index.js"
5655
}
5756
}
5857
</script>
5958

6059
<script type="module">
6160
import * as linera from '@linera/client';
62-
import { PrivateKey } from '@linera/signer';
6361
import { ethers } from 'ethers';
6462

65-
async function run() {
66-
await linera.default();
63+
async function run() {
64+
console.log(linera);
65+
await linera.initialize();
6766
const faucet = await new linera.Faucet(import.meta.env.LINERA_FAUCET_URL);
6867
const mnemonic = ethers.Wallet.createRandom().mnemonic.phrase;
69-
const signer = PrivateKey.fromMnemonic(mnemonic);
68+
const signer = linera.PrivateKeySigner.fromMnemonic(mnemonic);
7069
const wallet = await faucet.createWallet();
7170
const owner = await signer.address();
7271
document.getElementById('owner').innerText = owner;
7372
document.getElementById('chain-id').innerText = await faucet.claimChain(wallet, owner);
7473
const client = await new linera.Client(wallet, signer);
75-
const counter = await client.frontend().application(import.meta.env.LINERA_APPLICATION_ID);
74+
const counter = await client.application(import.meta.env.LINERA_APPLICATION_ID);
7675
const logs = document.getElementById('logs');
7776
const incrementButton = document.getElementById('increment-btn');
7877
const blockTemplate = document.getElementById('block-template');

examples/counter/metamask/index.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,25 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting chain…</code>
5454
<script type="importmap">
5555
{
5656
"imports": {
57-
"@linera/client": "./js/@linera/client/linera_web.js",
58-
"@linera/signer": "./js/@linera/signer/index.js"
57+
"@linera/client": "./js/@linera/client/dist/index.js"
5958
}
6059
}
6160
</script>
6261

6362
<script type="module">
6463
import * as linera from '@linera/client';
65-
import * as linera_signer from '@linera/signer';
64+
import * as linera_metamask from '@linera/metamask';
6665

6766
async function run() {
68-
await linera.default();
67+
await linera.initialize();
6968
const faucet = await new linera.Faucet(import.meta.env.LINERA_FAUCET_URL);
70-
const signer = await new linera_signer.MetaMask();
69+
const signer = await new linera_metamask.Signer();
7170
const wallet = await faucet.createWallet();
7271
const owner = await signer.address();
7372
document.getElementById('owner').innerText = owner;
7473
document.getElementById('chain-id').innerText = await faucet.claimChain(wallet, owner);
7574
const client = await new linera.Client(wallet, signer);
76-
const counter = await client.frontend().application(import.meta.env.LINERA_APPLICATION_ID);
75+
const counter = await client.application(import.meta.env.LINERA_APPLICATION_ID);
7776
const logs = document.getElementById('logs');
7877
const incrementButton = document.getElementById('increment-btn');
7978
const blockTemplate = document.getElementById('block-template');

examples/counter/metamask/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@linera/examples/hosted-counter-metamask",
2+
"name": "@linera/examples/metamask",
33
"private": true,
44
"author": "Linera <[email protected]>",
55
"license": "Apache-2.0",
@@ -13,7 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@linera/client": "workspace:*",
16-
"@linera/signer": "workspace:*"
16+
"@linera/metamask": "workspace:*"
1717
},
1818
"devDependencies": {
1919
"vite": "^5.4.11"

examples/counter/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@linera/examples/hosted-counter",
2+
"name": "@linera/examples/counter",
33
"private": true,
44
"author": "Linera <[email protected]>",
55
"license": "Apache-2.0",
@@ -13,10 +13,9 @@
1313
},
1414
"dependencies": {
1515
"@linera/client": "workspace:*",
16-
"@linera/signer": "workspace:*",
17-
"ethers": "^6.14.3"
16+
"ethers": "^6.15.0"
1817
},
1918
"devDependencies": {
20-
"vite": "^5.4.11"
19+
"vite": "^7.1.7"
2120
}
2221
}

examples/native-fungible/index.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,13 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
142142
<script type="importmap">
143143
{
144144
"imports": {
145-
"@linera/client": "./js/@linera/client/linera_web.js",
146-
"@linera/signer": "./js/@linera/signer/index.js"
145+
"@linera/client": "./js/@linera/client/index.js",
147146
}
148147
}
149148
</script>
150149

151150
<script type="module">
152151
import * as linera from '@linera/client';
153-
import { PrivateKey } from '@linera/signer';
154152
import { ethers } from 'ethers';
155153

156154
const gql = (query, variables = {}) => JSON.stringify({ query, variables });
@@ -225,18 +223,18 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting a new microchai
225223
navigator.clipboard.writeText(document.querySelector('#account-id').textContent);
226224
});
227225

228-
await linera.default();
226+
await linera.initialize();
229227
const faucet = await new linera.Faucet(import.meta.env.LINERA_FAUCET_URL);
230228
const mnemonic = ethers.Wallet.createRandom().mnemonic.phrase;
231-
const signer = PrivateKey.fromMnemonic(mnemonic);
229+
const signer = linera.PrivateKeySigner.fromMnemonic(mnemonic);
232230
const wallet = await faucet.createWallet();
233231
const owner = signer.address();
234232
const chainId = await faucet.claimChain(wallet, owner);
235233
const client = await new linera.Client(wallet, signer);
236234
document.querySelector('#chain-id').innerText = chainId;
237235
document.querySelector('#owner').innerText = owner;
238236

239-
const application = await client.frontend().application(import.meta.env.LINERA_APPLICATION_ID);
237+
const application = await client.application(import.meta.env.LINERA_APPLICATION_ID);
240238

241239
await updateBalance(application, owner);
242240

examples/native-fungible/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@linera/examples/hosted-fungible",
2+
"name": "@linera/examples/fungible",
33
"private": true,
44
"author": "Linera <[email protected]>",
55
"license": "Apache-2.0",
@@ -13,7 +13,6 @@
1313
},
1414
"dependencies": {
1515
"@linera/client": "workspace:*",
16-
"@linera/signer": "workspace:*",
1716
"ethers": "^6.14.3"
1817
},
1918
"devDependencies": {

0 commit comments

Comments
 (0)