Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions basics/serviceEndpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ConfigService, DidHelpers } from '@kiltprotocol/sdk-js'
import { DidDocument, KiltAddress, SignerInterface } from '@kiltprotocol/types'

const serviceId = '#example-service-id'

export async function addServiceEndpoints(
didDocument: DidDocument,
signers: SignerInterface[],
submitter: SignerInterface<'Ed25519', KiltAddress>
): Promise<void> {
const api = ConfigService.get('api')

const transactionHandler = DidHelpers.addService({
api,
didDocument,
signers,
submitter,
service: {
id: serviceId,
type: ['example-type'],
serviceEndpoint: ['https://example.com/endpoint'],
},
}).submit()

// Check if the result is rejected or confirmed
if (result.isRejected) {
throw new Error(`Service added failed: ${result.asRejected.error}`)
}
if (result.isConfirmed) {
console.log('Service added successfully')
}
}

export async function removeServiceEndpoints(
didDocument: DidDocument,
signers: SignerInterface[],
submitter: SignerInterface<'Ed25519', KiltAddress>
): Promise<void> {
const api = ConfigService.get('api')

const transactionHandler = DidHelpers.removeService({
api,
didDocument,
signers: signers,
submitter: submitter,
id: serviceId,
}).submit()
// Check if the result is rejected or confirmed
if (result.asRejected) {
throw new Error(`Service removal failed: ${result.asRejected.error}`)
}
if (result.asConfirmed) {
console.log('Service removed successfully')
}
Comment on lines +49 to +54

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated this as per your comments.

However, I am getting this response.

Property 'isConfirmed' does not exist on type 'TransactionResult'. Did you mean 'asConfirmed'?ts(2551)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah we may not have this, in which case it would just be result.status === "confirmed"

}
11 changes: 10 additions & 1 deletion basics/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { Balances, KiltAddress, SignerInterface } from '@kiltprotocol/types'
import { issueCredential } from './issueCredential.ts'
import { claimW3N } from './claimW3N.ts'
import { releaseW3N } from './releaseW3N.ts'
import {
addServiceEndpoints,
removeServiceEndpoints,
} from './serviceEndpoints.ts'

async function runAll(): Promise<void> {
let api = await Kilt.connect('wss://peregrine.kilt.io/')
Expand Down Expand Up @@ -50,7 +54,12 @@ async function runAll(): Promise<void> {
)

console.log('Credential', credential)

await addServiceEndpoints(holderDid.didDocument, holderDid.signers, submitter)
await removeServiceEndpoints(
holderDid.didDocument,
holderDid.signers,
submitter
)
await api.disconnect()
console.log('disconnected')
}
Expand Down