forked from raid-guild/headline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublishModals.js
133 lines (115 loc) · 3.87 KB
/
publishModals.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import "dotenv/config"; // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
import { CeramicClient } from "@ceramicnetwork/http-client";
import { writeFile } from "node:fs/promises";
import { ModelManager } from "@glazed/devtools";
import { DID } from "dids";
import { Ed25519Provider } from "key-did-provider-ed25519";
import { getResolver } from "key-did-resolver";
import { fromString } from "uint8arrays";
import publicationSchema from "./src/schemas/publication.json";
import publishRegistrySchema from "./src/schemas/publishedRegistry.json";
import articleSchema from "./src/schemas/article.json";
import articleRegistrySchema from "./src/schemas/articleRegistry.json";
// The key must be provided as an environment variable
const key = fromString(process.env["SEED"], "base16");
// Create and authenticate the DID
const did = new DID({
provider: new Ed25519Provider(key),
resolver: getResolver(),
});
await did.authenticate();
// Connect to the local Ceramic node
const ceramic = new CeramicClient("https://ceramic-test.viaheadline.xyz");
ceramic.did = did;
// Create a manager for the model
const manager = new ModelManager(ceramic);
const publicationSchemaID = await manager.createSchema(
"Publication",
publicationSchema
);
const articleSchemaID = await manager.createSchema("Article", articleSchema);
const articleRegistrySchemaID = await manager.createSchema(
"ArticleRegistry",
articleRegistrySchema
);
const publishRegistrySchemaID = await manager.createSchema(
"PublishRegistry",
publishRegistrySchema
);
// Create the definition using the created schema ID
await manager.createDefinition("publication", {
name: "My publication",
description: "A newsletter publication",
schema: manager.getSchemaURL(publicationSchemaID),
});
await manager.createDefinition("article", {
name: "A unstack article",
description: "A newsletter article",
schema: manager.getSchemaURL(articleSchemaID),
});
await manager.createDefinition("articleRegistry", {
name: "Article registry",
description: "A registry of all unstack articles for a given publication",
schema: manager.getSchemaURL(articleRegistrySchemaID),
});
await manager.createDefinition("publishRegistry", {
name: "Publish registry",
description: "A registry of all published unstack articles",
schema: manager.getSchemaURL(publishRegistrySchemaID),
});
const accessControlConditions = [
{
contractAddress: "",
standardContractType: "",
chain: "xdai",
method: "",
parameters: [":userAddress"],
returnValueTest: {
comparator: "=",
value: "0x50e2dac5e78B5905CB09495547452cEE64426db2",
},
},
];
await manager.createTile(
"examplePublication",
{
name: "Example",
about: "Example publication",
draftAccess: { encryptedSymmetricKey: "key", accessControlConditions },
publishAccess: { encryptedSymmetricKey: "key", accessControlConditions },
},
{ schema: manager.getSchemaURL(publicationSchemaID) }
);
await manager.createTile(
"exampleArticle",
{
publicationUrl: "ipfs://hi",
title: "hi",
createdAt: "2019-10-12T07:20:50.52Z",
status: "draft",
},
{ schema: manager.getSchemaURL(articleSchemaID) }
);
await manager.createTile(
"exampleArticleRegistry",
{
k2t6wyfsu4pfxcjnx1gg5q37xywk5gihcjwrdrbohacqr25emxg4p05mpjvnkc:
"k2t6wyfsu4pfxcjnx1gg5q37xywk5gihcjwrdrbohacqr25emxg4p05mpjvnkc",
},
{ schema: manager.getSchemaURL(articleRegistrySchemaID) }
);
await manager.createTile(
"examplePublishRegistry",
{
k2t6wyfsu4pfxcjnx1gg5q37xywk5gihcjwrdrbohacqr25emxg4p05mpjvnkc:
"k2t6wyfsu4pfxcjnx1gg5q37xywk5gihcjwrdrbohacqr25emxg4p05mpjvnkc",
},
{ schema: manager.getSchemaURL(articleRegistrySchemaID) }
);
// Publish model to Ceramic node
const model = await manager.toPublished();
// Write published model to JSON file
await writeFile(
"./src/schemas/published/models_testnet.json",
JSON.stringify(model)
);