@bcrl/wallet-sdk
v0.0.25
Published
An SDK to interact with the wallet.
Downloads
50
Readme
Agent SDK
An SDK to interact with the wallet.
install either with npm or yarn
npm install @bcrl/wallet-sdk
Or include the following script tag in your html
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@bcrl/wallet-sdk@latest/index.js"
></script>
To interact with the agent, you need a valid token for the authorization. You also need to pass the agent url and the wallet url.
JSfiddle
To play around with a minimal example, you can use this JSfiddle
Issuance
In case of issuance, you need also to pass an array of credentials.
<button id="issue">Issue</button>
<img id="code" />
<a id="link" target="_blank">Click here</a>
document.getElementById('issue').addEventListener('click', () => {
const token = '';
const wallet = '';
const credentials = [];
const issuer = new Issuer(token, wallet);
issuer
.issue({
credentialDataSupplierInput: {},
credentials,,
user_pin_required: false,
})
.then((res) => {
const qrcode = `https://api.qrserver.com/v1/create-qr-code/?size=300x300&data=${encodeURIComponent(
res.url
)}`;
document.getElementById('code').setAttribute('src', qrcode);
document.getElementById('link').setAttribute('href', res.url);
const interval = setInterval(async () => {
const status = await issuer.getStatus(res.id);
switch (status) {
case 'CREDENTIAL_ISSUED':
clearInterval(interval);
alert('done :)');
break;
case 'ERROR':
clearInterval(interval);
alert('error :(');
break;
}
}, 1000);
});
});
Verification
In case of verification, you need to pass the id of the credential you want to verify.
<button id="verify">Verify</button>
<img id="code" />
<a id="link" target="_blank">Click here</a>
document.getElementById('verify').addEventListener('click', () => {
const token = '';
const wallet = '';
const id = '';
const verifier = new Verifier(token, wallet);
verifier
.verify({
id,
})
.then((res) => {
const qrcode = `https://api.qrserver.com/v1/create-qr-code/?size=300x300&data=${encodeURIComponent(
res.url
)}`;
document.getElementById('code').setAttribute('src', qrcode);
document.getElementById('link').setAttribute('href', res.url);
const interval = setInterval(async () => {
const status = await verifier.getStatus(res.id, id);
let values;
switch (status.status) {
case 'verified':
clearInterval(interval);
if (Array.isArray(status.payload.vp_token)) {
values = status.payload.vp_token.map((vp) =>
verifier.handleVp(vp)
);
} else {
values = verifier.handleVp(status.payload.vp_token);
}
alert(JSON.stringify(values, null, 2));
break;
case 'error':
clearInterval(interval);
break;
}
}, 1000);
});
});
Remote agent
you can also use a service token to get access to the remote agent:
import { TokenConfig, getRemoteAgent } from '@bcrl/wallet-sdk';
const auth: TokenConfig = {
clientId: '',
clientSecret: '',
};
getRemoteAgent('https://agent.web3.yanacocha.fit.fraunhofer.de/fit', auth).then(
(agent) => {}
);