Hi I would like to ask for some help with the following issue:
I am trying to complete this tutorial to create a simple script that creates a stream, then updates it. Originally I wanted to use the HTTP API, but I didn’t get any answers on how to authenticate so I decided to try with the JS client until I can solve that issue.
So I am using the following code:
import { CeramicClient } from '@ceramicnetwork/http-client'
import { DID } from 'dids'
import { getResolver as getKeyResolver } from 'key-did-resolver'
import { getResolver as get3IDResolver } from '@ceramicnetwork/3id-did-resolver'
import { ThreeIdProvider } from '@3id/did-provider'
import { TileDocument } from '@ceramicnetwork/stream-tile'
function getPermission(request) {
return Promise.resolve(request.payload.paths)
}
// You need an instance of Ceramic to call getResolver.
// This can be either @ceramicnetwork/core or @ceramicnetwork/http-client.
// You can also set an address for your own ethr-did-registry contract
const API_URL = 'https://ceramic-clay.3boxlabs.com'
const ceramic = new CeramicClient(API_URL)
async function authenticateWithSecret(authSecret) {
const ceramic = new CeramicClient()
const threeID = await ThreeIdProvider.create({
authId: 'myAuthID',
authSecret,
// See the section above about permissions management
getPermission: (request) => Promise.resolve(request.payload.paths),
})
const did = new DID({
provider: threeID.getDidProvider(),
resolver: {
...get3IDResolver(ceramic),
...getKeyResolver(),
},
})
// Authenticate the DID using the 3ID provider
await did.authenticate()
ceramic.did = did
console.log(ceramic.did)
}
const schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Reward",
"type": "object",
"properties": {
"title": { "type": "string" },
"message": { "type": "string" }
},
"required": [
"message",
"title"
]
}
const metadata = {
controllers: [ceramic.did] // this will set yourself as the controller of the schema const did = 'z6MksgkPHLpq7x9aEVSRgmo41ssaviBKmcV7rULmJqza9iwm'
}
const rewardSchema = await TileDocument.create(ceramic, schema, metadata)
const reward = await TileDocument.create(ceramic, {
title: 'Hello',
message: 'world!'
}, {
controllers: [ceramic.did],
family: 'Rewards',
schema: rewardSchema.commitId.toString(),
})
console.log(reward.state)
And I am receiving the following error message:
file:///C:/Users/ceramic_network/latency/node_modules/@ceramicnetwork/stream-tile/lib/tile-document.js:59
throw new Error(`No DID provided`);
^
Error: No DID provided
at getAuthenticatedDID (file:///C:/Users/ceramic_network/latency/node_modules/@ceramicnetwork/stream-tile/lib/tile-document.js:59:15)
at TileDocument._signDagJWS (file:///C:/Users/ceramic_network/latency/node_modules/@ceramicnetwork/stream-tile/lib/tile-document.js:205:27)
at TileDocument.makeGenesis (file:///C:/Users/ceramic_network/latency/node_modules/@ceramicnetwork/stream-tile/lib/tile-document.js:202:31)
at TileDocument.create (file:///C:/Users/ceramic_network/latency/node_modules/@ceramicnetwork/stream-tile/lib/tile-document.js:92:45)
at file:///C:/Users/ceramic_network/latency/test.js:67:41
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
Node.js v18.12.0
I was trying to provide the DID myself in the code but then I quickly run into the error code that says: Only one controller needs to be specified. I tried to provide the authsecret in different ways but none seems to work, and that doesnt seem to be the issue. I haven’t used JS too much that is why I originally wanted to use the HTTP API.
Could anyone help and explain to me what is the mistake in the code?