@ticketto/web-stub
v1.4.7
Published
A stub-based, web-scoped implementation of The Ticketto Protocol
Downloads
55
Maintainers
Readme
Libticketto: Stub Web
This library implements The Ticketto Protocol, based on an in-memory (design goal, use dedicated storage, like the IndexedDB API).
Usage
First, make sure your client supports IndexedDB.
Then, before starting the application (at the entrypoint), import reflect-metadata:
import 'reflect-metadata';Setting up the WebStub consumer
- Define the configuration. Consider that your stub
AccountProvidermust return the actualAccountIdassociated to the account logged-in on your application. Also, the signer must receive aUint8Array, and return aPromise<Uint8Array>that contains the signed transaction. For local testing purposes, we can use this demo:
// src/config.ts
import { ClientConfig } from '@ticketto/protocol';
export const defaultConfig: ClientConfig<Uint8Array> = {
accountProvider: {
getAccountId: () => "5DD8bv4RnTDuJt47SAjpWMT78N7gfBQNF2YiZpVUgbXkizMG",
sign: (payload: Uint8Array) => Promise.resolve(payload),
},
};- Initialize the ticketto client, passing the
TickettoWebStubConsumeras well as the config.
// src/index.ts
import { TickettoClientBuilder } from '@ticketto/protocol';
import { TickettoWebStubConsumer } from '@ticketto/web-stub';
import { defaultConfig } from './config.ts'
const client = await new TickettoClientBuilder()
.withConsumer(TickettoWebStubConsumer)
.withConfig(defaultConfig)
.build();- Enjoy!
// Example of the client validating and submitting the contents of an attendance QR (let's call it `input`).
/** In our example, the QR payload is a base-64 encoded input representing the call */
const qr = await readQrCode();
const input: Uint8Array = fromBase64();
await client.tickets.calls.submitAttendanceCall(input);