o1-labs / o1js

TypeScript framework for zk-SNARKs and zkApps
https://docs.minaprotocol.com/en/zkapps/how-to-write-a-zkapp
Apache License 2.0
524 stars 118 forks source link

Feature request: Adding devnet to mina-signer #1600

Closed iam-dev closed 6 months ago

iam-dev commented 6 months ago

The ability to use devnet using mina-signer

import Client from 'mina-signer';
const client = new Client({ network: 'devnet' });
mitschabaude commented 6 months ago

The correct network id to use with devnet is 'testnet', so we already support devnet.

The network id is supposed to prevent replays of testnet transactions on mainnet. So it only needs to distinguish between testnet and mainnet, not what kind of testnet (the custom option is intended to support alternative mainnets, like L2s)

iam-dev commented 6 months ago

This is misleading because auro wallet gives back devnet as connected network, which mean mina-signer will error using devnet

const requestedNetwork = await (window as any)?.mina?.requestNetwork().catch((err: any) => err);
iam-dev commented 6 months ago

My use case will be:

mitschabaude commented 6 months ago

@iam-dev I guess the answer is, requestedNetwork returned by Auro wallet just doesn't have the same meaning as the network parameter of mina-signer, that's why you can't plug in one of them into the other.

In the case of mina-signer, it just wants to know whether this is a testnet or a mainnet, and nothing else. We should document that better.

Adapting your use case is easy: If Auro returns something else than "mainnet", use "testnet" in mina-signer.

mitschabaude commented 6 months ago

@iam-dev another thing to note. If you aren't signing transactions, but just use signFields() or verifyFields() from mina-signer, to handle signatures which are consumed by zkapps, then the network parameter doesn't matter at all. It won't be used.

mitschabaude commented 6 months ago

Our zkApp verify this signature using mina-signer

@iam-dev finally, I hope it's obvious but just to make sure: mina-signer is not creating constraints and can't be used to verify a signature as part of a zkApp @method

iam-dev commented 6 months ago

It's clear for me now, I had a backend working that validate signature to signin with Web3, which also uses mina-signer. I solved it with a workaround using "testnet" and works like a charms. I guess this is a workable workaround

iam-dev commented 6 months ago

Thanks @mitschabaude for clearing this up for me