-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
63 lines (56 loc) · 2.07 KB
/
index.ts
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
import { CeramicClient } from '@ceramicnetwork/http-client'
import { Model, ModelDefinition } from '@ceramicnetwork/stream-model'
import { CeramicApi } from '@ceramicnetwork/common'
import { Ed25519Provider } from 'key-did-provider-ed25519'
import * as ThreeIdResolver from '@ceramicnetwork/3id-did-resolver'
import * as KeyDidResolver from 'key-did-resolver'
import * as PkhDidResolver from 'pkh-did-resolver'
import { Resolver } from 'did-resolver'
import { DID } from 'dids'
import { fromString } from 'uint8arrays'
import { ModelInstanceDocument } from '@ceramicnetwork/stream-model-instance'
import { StreamID } from '@ceramicnetwork/streamid'
export function createDid(ceramic: CeramicApi, seed: string): DID {
const provider = new Ed25519Provider(fromString(seed, 'base16'))
const keyDidResolver = KeyDidResolver.getResolver()
const pkhDidResolver = PkhDidResolver.getResolver()
const threeIdResolver = ThreeIdResolver.getResolver(ceramic)
const resolver = new Resolver({
...threeIdResolver,
...pkhDidResolver,
...keyDidResolver,
})
return new DID({ provider, resolver })
}
const MODEL_DEFINITION: ModelDefinition = {
name: 'MyModel',
version: Model.VERSION,
accountRelation: { type: 'list' },
schema: {
$schema: 'https://json-schema.org/draft/2020-12/schema',
type: 'object',
additionalProperties: false,
properties: {
myData: {
type: 'integer',
maximum: 10000,
minimum: 0,
},
},
required: ['myData'],
},
}
const setupCeramicClient = async (): Promise<CeramicClient> => {
const apiUrl = process.env.CERAMIC_URL
const pk = process.env.PRIVATE_KEY || ""
const ceramicClient = new CeramicClient(apiUrl)
const did = await createDid(ceramicClient, pk)
await did.authenticate()
ceramicClient.did = did
return ceramicClient
}
const modelIdStr = 'kjzl6hvfrbw6c845kvo6rq3zbv0uin9vo0slxq8aavx5nbvcxtppe2qga7d8abx'
let ceramicClient: CeramicClient
ceramicClient = await setupCeramicClient()
const indexedModels = await ceramicClient.admin.getIndexedModels()
console.log('INDEXED MODELS', indexedModels)