Create DID Session in node with ethers

Hi I am following this tutorial and I want to create it without the front-end. Only in JS without Metamask interaction. Is that possible?
I would like to use provider and address with ethers and private keys stored in my .env

This is how my code looks like now

import { DIDSession } from "@glazed/did-session";
//import Web3 from "web3";
import { ethers } from "ethers";
import { EthereumWebAuth, getAccountId } from "@didtools/pkh-ethereum";
import { EthereumAuthProvider } from "@ceramicnetwork/blockchain-utils-linking";

import { config } from "dotenv";
config({ path: "/Users/andy/Keys/generalKeys.env" }).parsed;

async function authenticate() {
  const ethereumProvider = new ethers.providers.JsonRpcProvider(
    String(process.env.URL_MUMBAI)
  );

  const account = new ethers.Wallet(
    process.env.GOVERNOR_PRIVATE_KEY,
    ethereumProvider
  );

  const authProvider = new EthereumAuthProvider(ethereumProvider, account);

  console.log(authProvider);

  const session = new DIDSession({ authProvider });

  console.log(session);

  const did = await session.authorize();

  // ceramic.did = did;
}

await authenticate();

And this is how my authProvider object looks now

EthereumAuthProvider {
  provider: JsonRpcProvider {
    _isProvider: true,
    _events: [],
    _emitted: { block: -2 },
    disableCcipRead: false,
    formatter: Formatter { formats: [Object] },
    anyNetwork: false,
    _networkPromise: Promise { <pending> },
    _maxInternalBlockNumber: -1024,
    _lastBlockNumber: -2,
    _maxFilterBlockRange: 10,
    _pollingInterval: 4000,
    _fastQueryDate: 0,
    connection: {
      url: 'https://polygon-mumbai.infura.io/v3/....'
    },
    _nextId: 42
  },
  address: Wallet {
    _isSigner: true,
    _signingKey: [Function (anonymous)],
    _mnemonic: [Function (anonymous)],
    address: '0xda97f787dd561C1115ba5E95B80CfAb3f7Dd7001',
    provider: JsonRpcProvider {
      _isProvider: true,
      _events: [],
      _emitted: [Object],
      disableCcipRead: false,
      formatter: [Formatter],
      anyNetwork: false,
      _networkPromise: [Promise],
      _maxInternalBlockNumber: -1024,
      _lastBlockNumber: -2,
      _maxFilterBlockRange: 10,
      _pollingInterval: 4000,
      _fastQueryDate: 0,
      connection: [Object],
      _nextId: 42
    }
  },
  opts: {},
  isAuthProvider: true
}

And this is the error I get

Error: Missing parameter 'domain'
    at EthereumAuthProvider.requestCapability (file:///Users/andy/my_repos/Tutorials/Ceramic/node_modules/@ceramicnetwork/blockchain-utils-linking/lib/ethereum.js:52:19)
    at DIDSession.authorize (file:///Users/andy/my_repos/Tutorials/Ceramic/node_modules/@glazed/did-session/dist/index.js:209:94)
    at async authenticateWithEthereum (file:///Users/andy/my_repos/Tutorials/Ceramic/did-sessions.js:28:15)
    at async file:///Users/andy/my_repos/Tutorials/Ceramic/did-sessions.js:33:1

@zfer can you take a look?

you just have to pass the domain option, reference the bottom of the configuration section here - js-did/packages/did-session at main · ceramicnetwork/js-did · GitHub

you can also update to did-session v1 as most docs reference now, including the readme linked, you would use import { EthereumNodeAuth, getAccountId } from '@didtools/pkh-ethereum' similar to EthereumWebAuth

more docs on authmethods coming shortly

Thanks for your reply, still cannot make it work. But we can close this as

  1. I found a way around this using Ed25519Provider
// create and authenticate DID
async function createAndAuthenticateDID(seed) {
  const key = fromString(seed, "utf-8");

  // Create and authenticate the DID
  const did = new DID({
    provider: new Ed25519Provider(key),
    resolver: getResolver(),
  });
  await did.authenticate();
  return did;
}
  1. At one point I will still need to use MetaMask for real user auth. So then I can follow the standard approach.
    Many thanks anyways!

Gm, I am going through Module: pkh-ethereum | Decentralized Identifiers (DIDs) docs
Unfortunately, InfuraProvider from ethers does not work with getAccountId

Any workarounds available>3?

Got stuck debugging at safeSend

because InfuraProvider does not such properties: request, sendAsync or send

However, the error is still not thrown

It returns 404