Error: ed25519: seed must be 32 bytes when authenticating via script - Solved

I created a did key locally with glaze did:create. I then used the snippet as described here Key DID - Ceramic Developers

// `seed` must be a 32-byte long Uint8Array
async function authenticateCeramic(seed) {
    console.log(seed);
    const provider = new Ed25519Provider(seed);
    const did = new DID({ provider, resolver: getResolver() });
    // Authenticate the DID with the provider
    await did.authenticate();
    // The Ceramic client can create and update streams using the authenticated DID
    ceramic.did = did;
}

When I call that function with

Promise.resolve(
    authenticateCeramic(
        new TextEncoder().encode("my-seed-goes-here")
    )
);

It gives me “Error: ed25519: seed must be 32 bytes”. The seed generated from glaze did:create is 64 characters long and converted to a UintArray with a length of 64 (bytes?). When I chop the seed in half it does seem to work. However that seed can’t be used to create a new key with glaze did:create --key <half the seed>. I then get the error Error: ed25519: seed must be 32 bytes.

So I’m not sure what’s going on. Is seed generated with glaze did:create a 32 byte string? (64 characters?) Or do I only need to provide the first 32 characters as a UintArray to the createDocument function?

I figured it out. The seed had to be base16 encoded:

import { fromString } from "uint8arrays";
...
const seed = fromString(
    "<64 character seed>",
    "base16"
);

More info can be found here (switch between cli and script tabs) Build a note-taking app with Glaze - Ceramic Developers

2 Likes