@ula-aca/schema
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Universal Ledger Agent - Aries Cloudagent Schema Plugin

npm (scoped)

This package handles everything that has to do with schemas in Hyperledger Aries. It allows to create and retrieve schemas from the ledger connected to the Aries Cloudagent.

Usage

SchemaController

import { EventHandler } from 'universal-ledger-agent'
import { SchemaController } from '@ula-aca/schema'

const schemaController = new SchemaController({
  basePath: 'https://aca-py-api.com'
})

const eventHandler = new EventHandler([schemaController])

@ula-aca/schema/get-schema-by-id

Gets a schema from the ledger

import { EventHandler, UlaResponse } from 'universal-ledger-agent'
import {
  SchemaController,
  GetSchemaByIdMessage,
  SchemaMessageTypes
} from '@ula-aca/schema'

const schemaController = new SchemaController({
  basePath: 'https://aca-py-api.com'
})

const eventHandler = new EventHandler([schemaController])

const message: GetSchemaByIdMessage = {
  type: SchemaMessageTypes.GET_SCHEMA_BY_ID,
  body: {
    schema_id: 'WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0'
  }
}

eventHandler.processMsg(message, (response: UlaResponse) => {
  if (response.statusCode < 200 || response.statusCode >= 300) {
    // error
  } else {
    // response.body is response from /schemas/{id} api endpoint in aca-py
    // https://ula-aca.github.io/aries-cloudagent-interface-javascript/#/schema/get_schemas__id_
    const result: GetSchemaByIdResult = response.body
  }
})

@ula-aca/schema/get-created-schemas

Search for matching schema that agent originated

import { EventHandler, UlaResponse } from 'universal-ledger-agent'
import {
  SchemaController,
  GetCreatedSchemasMessage,
  SchemaMessageTypes
} from '@ula-aca/schema'

const schemaController = new SchemaController({
  basePath: 'https://aca-py-api.com'
})

const eventHandler = new EventHandler([schemaController])

const message: GetCreatedSchemasMessage = {
  type: SchemaMessageTypes.GET_CREATED_SCHEMAS,
  body: {
    // schema_id: '',
    // schema_issuer_did: '',
    // schema_name: '',
    // schema_version: ''
  }
}

eventHandler.processMsg(message, (response: UlaResponse) => {
  if (response.statusCode < 200 || response.statusCode >= 300) {
    // error
  } else {
    // response.body is response from /schemas/created api endpoint in aca-py
    // https://ula-aca.github.io/aries-cloudagent-interface-javascript/#/schema/get_schemas_created
    const result: GetCreatedSchemasResult = response.body
  }
})

@ula-aca/schema/create-schema

Sends a schema to the ledger

import { EventHandler, UlaResponse } from 'universal-ledger-agent'
import {
  SchemaController,
  CreateSchemaMessage,
  SchemaMessageTypes
} from '@ula-aca/schema'

const schemaController = new SchemaController({
  basePath: 'https://aca-py-api.com'
})

const eventHandler = new EventHandler([schemaController])

const message: CreateSchemaMessage = {
  type: SchemaMessageTypes.CREATE_SCHEMA,
  body: {
    schema_name: 'ExampleSchema',
    schema_version: '1.0',
    attributes: ['first_name', 'last_name']
  }
}

eventHandler.processMsg(message, (response: UlaResponse) => {
  if (response.statusCode < 200 || response.statusCode >= 300) {
    // error
  } else {
    // response.body is response from /schemas post request api endpoint in aca-py
    // https://ula-aca.github.io/aries-cloudagent-interface-javascript/#/schema/post_schemas
    const result: CreateSchemaResult = response.body
  }
})

Examples

For example usage see the examples/ directory.

Package Sidebar

Install

npm i @ula-aca/schema

Weekly Downloads

0

Version

0.0.2

License

Apache-2.0

Unpacked Size

32.4 kB

Total Files

25

Last publish

Collaborators

  • timoglastra