Here is a full script demonstrating the error based off this code found linked in the ceramic projects on github: TheGame/create-model.mjs at f5295c324244f2973ea419c588e784c142a8091b · MetaFam/TheGame · GitHub. This is the most recent example project listed in the documentation, so this initialization flow generates aliases properly, but the initial error continues to persist.
import { CeramicClient } from "@ceramicnetwork/http-client";
import { DataModel } from "@glazed/datamodel";
import { ModelManager } from "@glazed/devtools";
import { DIDDataStore } from "@glazed/did-datastore";
import { TileLoader } from "@glazed/tile-loader";
import { DID } from "dids";
import { Ed25519Provider } from "key-did-provider-ed25519";
import { getResolver } from "key-did-resolver";
import { fromString } from "uint8arrays/from-string";
const CERAMIC_URL = process.env.CERAMIC_URL || "http://localhost:7007";
const BackupSchema = {
$schema: "http://json-schema.org/draft-07/schema#",
title: "DataWalletBackup",
type: "object",
properties: {
header: {
type: "object",
properties: {
hash: {
type: "string",
},
timestamp: {
type: "number",
},
signature: {
type: "string",
},
},
},
blob: {
type: "object",
properties: {
data: {
type: "string",
},
initializationVector: {
type: "string",
},
},
},
},
};
const BackupIndexSchema = {
$schema: "http://json-schema.org/draft-07/schema#",
title: "BackupIndex",
type: "object",
properties: {
backups: {
type: "array",
items: {
type: "object",
properties: {
id: {
$ref: "#/definitions/CeramicStreamId",
},
timestamp: {
type: "integer",
},
},
},
},
},
definitions: {
CeramicStreamId: {
type: "string",
pattern: "^ceramic://.+(\\\\?version=.+)?",
maxLength: 150,
},
},
};
async function run() {
// The seed must be provided as an environment variable
const seed = fromString(
process.env.SEED ||
"SEED",
"base16",
); // node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
// Connect to the local Ceramic node
const ceramic = new CeramicClient(CERAMIC_URL);
const provider = new Ed25519Provider(seed);
const did = new DID({ provider, resolver: getResolver() });
await did.authenticate();
ceramic.did = did;
// Create a manager for the model
const manager = new ModelManager({ ceramic });
// Publish the two schemas
const [backupSchema, backupIndexSchema] = await Promise.all([
manager.createSchema("DataWalletBackup", { content: BackupSchema }),
manager.createSchema("BackupIndex", { content: BackupIndexSchema }),
]);
// Create the definition using the created schema ID
const backupsDefinition = await manager.createDefinition("backupIndex", {
name: "backupIndex",
description: "SDL Data Wallet Backup Index",
schema: manager.getSchemaURL(backupIndexSchema),
});
// Write model to JSON file
const modelAliases = await manager.deploy();
console.log(modelAliases);
// BEGIN TESTING
const loader = new TileLoader({ ceramic });
const dataModel = new DataModel({
loader: loader,
aliases: modelAliases,
});
const dataStore = new DIDDataStore({
ceramic,
loader,
model: dataModel,
});
const index = await dataStore.get("backupIndex");
console.log(index); // always null
// internal server error
const cid = await dataModel.createTile("DataWalletBackup", {
header: { hash: "hash", timestamp: 41, signature: "sig" },
blob: { data: "test", initializationVector: "initVector" },
});
// internal server error
await dataStore.set("backupIndex", {
backups: [{ id: cid, timestamp: 41 }],
});
// END TESTING
}
run().catch(console.error);