2.1.3-alpha.1635236188.0 • Published 4 years ago

@energyweb/origin-247-certificate v2.1.3-alpha.1635236188.0

Weekly downloads
-
License
-
Repository
-
Last release
4 years ago

Origin 24/7 SDK - Certificate module

Certificate module (and its CertificateService) allow to issue, transfer and claim certificates.

It enqueues and batches transactions, which is required for optimal blockchain work.

Specific requirements

Despite typical 24/7 SDK requirements and setup, you will need

  • Redis (For enqueueing we use bull package)

Installation

  1. Add peer runtime dependencies: yarn add @energyweb/issuer @energyweb/issuer-api
  2. For NestJS Bull please consult: https://docs.nestjs.com/techniques/queues and setup BullModule.forRoot.
  3. For migrations, please add entry to your package.json scripts section:

"typeorm:run:issuer": "node_modules/typeorm/cli.js migration:run --config node_modules/@energyweb/issuer-api/dist/js/ormconfig.js",

Which allows to run migration required by the module.

  1. Add TypeORM entities:
import { entities as IssuerEntities } from '@energyweb/issuer-api';

[...]

TypeOrmModule.forRoot({
  ...
  entities: [
    ...,
    ...IssuerEntities,
  ],
  ...
});

Usage

Import Certificate module into one of your applications modules:

import { CertificateModule } from '@energyweb/origin-247-certificate';

@Module({
    imports: [CertificateModule]
})
export class SomeModule {}

Use the service:

import { CertificateService, CERTIFICATE_SERVICE_TOKEN } from '@energyweb/origin-247-certificate';

/**
 * Because certificate entity allows to store custom data called "metadata"
 * user can provide typing for metadata.
 *
 * See README metadata section for more information.
 */
interface IMetadata {
  myCustomCertificateData: string;
}

export class SomeService {
  constructor(
    @Inject(CERTIFICATE_SERVICE_TOKEN)
    private certificateService: CertificateService<IMetadata>
  ) {}

  public async issueRandomCertificate(): Promise<void> {
    await this.certificateService.issue({
      ...
    });
  }
}

Metadata

Each certificate is able to store metadata information, which is used for storing custom payloads.

Therefore all certificate types (including service) imported from the module give user the ability to provide interface/type for that metadata (as generic type). This way metadata stays typed across application. It's best to create this type somewhere and reuse it across application.

Metadata is serialized internally via JSON.stringify therefore metadata has to be serializable. Any value accepted by JSON.stringify can be used as metadata (including null - which is default value for metadata field)

Environment configuration

Variable nameDefault valueDescription
CERTIFICATE_QUEUE_LOCK_DURATION240 * 1000 msHow long processor can lock given queue item before marking it stale (stalled queue items are rerun again) - change with caution
CERTIFICATE_QUEUE_DELAY10 * 1000 msHow long each queue item should wait before finishing it's processing - helps with some transaction nonce problems
4.1.4

3 years ago

4.1.3

3 years ago

4.1.5

3 years ago

4.1.2

3 years ago

4.1.1

3 years ago

4.1.0

3 years ago

4.0.0

4 years ago

3.4.0

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.0.0

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.1.0

4 years ago

2.2.0

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago

0.0.2-alpha.8.0

4 years ago

0.0.2-alpha.6.0

4 years ago

0.0.2-alpha.5.0

4 years ago

0.0.2-alpha.7.0

4 years ago

0.0.2-alpha.2.0

4 years ago

0.0.2-alpha.1.0

4 years ago