@did-connect/state
v2.2.4
Published
State machine for did-connect session
Downloads
107
Readme
Overview
This package leverages xstate to define the state machine of a DID Connect Session, can be used both in the browser and node.js environment. It's the foundation of DID Connect UX libraries of @did-connect/react
and @did-connect/vue
.
Install
npm install @did-connect/state
// or
yarn add @did-connect/state
Usage
const { interpret } = require('xstate');
const { createStateMachine } = require('@did-connect/state');
const stateHistory = [];
const { machine } = createStateMachine({
relayUrl: '/.well-known/service/api/connect/relay',
dispatch: (...args) => service.send.apply(service, args),
onConnect: (ctx, e) => {
return [];
},
onApprove: (ctx) => ({}),
onComplete: () => {},
onCancel: (ctx, e) => {
hasCanceled = true;
},
});
const service = interpret(machine).onTransition((state) => {
if (state.changed !== false) {
stateHistory.push(state.value);
}
});
service.start();
TODO: add node.js example for blocklet connect