did-provider-quick
Version:
Veramo plugin that can enable creation and control of did:quick identifiers.
64 lines • 2.22 kB
JavaScript
import Debug from 'debug';
import { createWitnessHash, getProof } from './utils/witnessApi.js';
import { Readable } from 'stream';
const debug = Debug('veramo:did-provider-quick:saveDIDQuickUpdate');
import { TurboFactory, } from "@ardrive/turbo-sdk";
import Arweave from "arweave";
const arweave = Arweave.init({
host: 'arweave.net',
port: 443,
protocol: 'https'
});
// dotenv.config();
export async function postPendingDIDQuickUpdates(batch, agent) {
const credentials = await agent.dataStoreORMGetVerifiableCredentials({
where: [
{
column: 'hash',
value: batch,
op: 'In',
},
],
});
const witnessedCredentials = [];
for (const credential of credentials) {
const witHash = createWitnessHash(credential.hash);
try {
const res = await getProof(witHash);
witnessedCredentials.push({
credential,
proof: { ...res, leafIndex: res.leafIndex.toString() }
});
}
catch (ex) {
console.log("witness proof not available.");
}
}
if (witnessedCredentials.length > 0) {
const jwk = JSON.parse(process.env.ARWEAVE_WALLET_JWK);
const turboAuthClient = TurboFactory.authenticated({
privateKey: jwk,
});
const credentialString = JSON.stringify(witnessedCredentials);
const uploadResult = await turboAuthClient.uploadFile({
fileStreamFactory: () => Readable.from(Buffer.from(credentialString)),
fileSizeFactory: () => Buffer.byteLength(credentialString),
signal: AbortSignal.timeout(10_000),
dataItemOpts: {
tags: [
{
name: 'Content-Type',
value: 'application/json',
},
{
name: 'DID-Quick-alpha',
value: 'Update',
},
],
},
});
console.log("uploadResult: ", uploadResult);
}
return { success: true };
}
//# sourceMappingURL=postPendingDIDQuickUpdates.js.map