-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit.ts
79 lines (62 loc) · 2.93 KB
/
edit.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Nautilus, AssetBuilder, ConsumerParameterBuilder, CredentialListTypes, ServiceBuilder, LifecycleStates } from '@deltadao/nautilus'
export async function editServicePrice(nautilus: Nautilus, did: string, newPrice: string) {
const aquariusAsset = await nautilus.getAquariusAsset(did)
const result = await nautilus.setServicePrice(aquariusAsset, aquariusAsset.services[0].id, newPrice)
console.log('Set new service price:', result)
}
export async function editToSaas(nautilus: Nautilus, did: string, redirectUrl: string, paymentMode: 'payperuse' | 'subscription'){
const aquariusAsset = await nautilus.getAquariusAsset(did)
const assetBuilder = new AssetBuilder(aquariusAsset)
// Setup an SaaS asset
const asset = assetBuilder.addAdditionalInformation({
...aquariusAsset.metadata.additionalInformation,
saas: {
redirectUrl,
paymentMode
}
}).build()
const result = await nautilus.edit(asset)
console.log('Edited asset as SaaS:', result)
}
export async function editTrustedAlgorithms(nautilus: Nautilus, did: string, trustedAlgorithms: string[], trustedPublishers: string[]){
const aquariusAsset = await nautilus.getAquariusAsset(did)
const assetBuilder = new AssetBuilder(aquariusAsset)
const serviceBuilder = new ServiceBuilder({ aquariusAsset, serviceId: aquariusAsset.services[0].id })
// Updating trusted publishers on a service
if (trustedPublishers.length > 0) {
for(const publisher of trustedPublishers){
serviceBuilder.addTrustedAlgorithmPublisher(publisher)
}
}
// Updating trusted algorithms on a service
if (trustedAlgorithms.length > 0) {
serviceBuilder.addTrustedAlgorithms(trustedAlgorithms.map(algo => ({ did: algo })))
}
const service = serviceBuilder.build()
const asset = assetBuilder.addService(service).build()
const result = await nautilus.edit(asset)
console.log('Edited trusted a;gorithms:', result)
}
export async function editAlgoMetadata(nautilus: Nautilus, did: string, tag: string, checksum: string) {
const aquariusAsset = await nautilus.getAquariusAsset(did)
const assetBuilder = new AssetBuilder(aquariusAsset)
const asset = assetBuilder.setAlgorithm({
...aquariusAsset.metadata.algorithm, // Start with existing algorithm metadata
container: {
...aquariusAsset.metadata.algorithm?.container,
// Updated container information
tag,
checksum
}
}).build()
const result = await nautilus.edit(asset)
console.log('Edit algo metadata:', result)
}
export async function revokeAsset(nautilus: Nautilus, did: string) {
const aquariusAsset = await nautilus.getAquariusAsset(did)
const tx = await nautilus.setAssetLifecycleState(
aquariusAsset,
LifecycleStates.REVOKED_BY_PUBLISHER
)
console.log('Edit lifecycle complete:', tx)
}