How to use @decentralized-identity/sidetree - 6 common examples

To help you get started, we’ve selected a few @decentralized-identity/sidetree examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github decentralized-identity / ion / src / bitcoin.ts View on Github external
app.use(router.routes())
  .use(router.allowedMethods());

// Handler to return bad request for all unhandled paths.
app.use((ctx, _next) => {
  ctx.response.status = 400;
});

const port = process.env.SIDETREE_BITCOIN_PORT || config.port;

// initialize the blockchain service and kick-off background tasks
let server: any;
let blockchainService: SidetreeBitcoinProcessor;
try {
  blockchainService = new SidetreeBitcoinProcessor(config);

  // SIDETREE_TEST_MODE enables unit testing of this file by bypassing blockchain service initialization.
  if (process.env.SIDETREE_TEST_MODE === 'true') {
    server = app.listen(port);
  } else {
    blockchainService.initialize()
    .then(() => {
      server = app.listen(port, () => {
        console.log(`Sidetree-Bitcoin node running on port: ${port}`);
      });
    })
    .catch((error) => {
      console.error(`Sidetree-Bitcoin node initialization failed with error: ${error}`);
      process.exit(1);
    });
  }
github decentralized-identity / ion / src / core.ts View on Github external
const setKoaResponse = (response: SidetreeResponseModel, koaResponse: Koa.Response) => {
  koaResponse.status = SidetreeResponse.toHttpStatus(response.status);

  if (response.body) {
    koaResponse.set('Content-Type', 'application/json');
    koaResponse.body = response.body;
  } else {
    // Need to set the body explicitly to empty string, else koa will echo the request as the response.
    koaResponse.body = '';
  }
};
github decentralized-identity / ion / src / ipfs.ts View on Github external
const setKoaResponse = (response: SidetreeResponseModel, koaResponse: Koa.Response, contentType?: string) => {
  koaResponse.status = SidetreeResponse.toHttpStatus(response.status);
  if (contentType) {
    koaResponse.set('Content-Type', contentType);
  } else {
    koaResponse.set('Content-Type', 'application/json');
  }

  if (response.body) {
    koaResponse.body = response.body;
  } else {
    // Need to set the body explicitly, otherwise Koa will return HTTP 204.
    koaResponse.body = '';
  }
};
github decentralized-identity / ion / src / core.ts View on Github external
SidetreeCore,
  SidetreeResponse,
  SidetreeResponseModel
} from '@decentralized-identity/sidetree';
import { ProtocolVersionModel } from '@decentralized-identity/sidetree/dist/lib/core/VersionManager';

/** Configuration used by this server. */
interface ServerConfig extends SidetreeConfig {
  /** Port to be used by the server. */
  port: number;
}

const config: ServerConfig = require('../json/core-config.json');
const protocolVersions: ProtocolVersionModel[] = require('../json/core-protocol-versioning.json');

const sidetreeCore = new SidetreeCore(config, protocolVersions);
const app = new Koa();

// Raw body parser.
app.use(async (ctx, next) => {
  ctx.body = await getRawBody(ctx.req);
  await next();
});

const router = new Router();
router.post('/did', async (ctx, _next) => {
  const response = await sidetreeCore.handleOperationRequest(ctx.body);
  setKoaResponse(response, ctx.response);
});

router.get('/did/:didOrDidDocument', async (ctx, _next) => {
  const response = await sidetreeCore.handleResolveRequest(ctx.params.didOrDidDocument);
github decentralized-identity / ion / src / ipfs.ts View on Github external
// Testing commiting and pushing branches

import {
  SidetreeIpfsService,
  SidetreeResponse,
  SidetreeResponseModel
} from '@decentralized-identity/sidetree';

const config: {
  /** Port number used by the service. */
  port: number;
  /** Timeout for fetch request. */
  fetchTimeoutInSeconds: number;
} = require('../json/ipfs-config.json');

const requestHandler = new SidetreeIpfsService(config.fetchTimeoutInSeconds);
const app = new Koa();

// Raw body parser.
app.use(async (ctx, next) => {
  ctx.body = await getRawBody(ctx.req);
  await next();
});

const router = new Router();

router.get('/version', async (ctx, _next) => {
  const response = await requestHandler.handleGetVersionRequest();
  setKoaResponse(response, ctx.response);
});

router.get('/:hash', async (ctx, _next) => {
github decentralized-identity / ion / src / bitcoin.ts View on Github external
server = app.listen(port);
  } else {
    blockchainService.initialize()
    .then(() => {
      server = app.listen(port, () => {
        console.log(`Sidetree-Bitcoin node running on port: ${port}`);
      });
    })
    .catch((error) => {
      console.error(`Sidetree-Bitcoin node initialization failed with error: ${error}`);
      process.exit(1);
    });
  }
} catch (error) {
  console.log('Is bitcoinWalletImportString valid? Consider using testnet key generated below:');
  console.log(SidetreeBitcoinProcessor.generatePrivateKey('testnet'));
  process.exit(1);
}
console.info('Sidetree bitcoin service configuration:');
console.info(config);

export {
  server,
  blockchainService
};

@decentralized-identity/sidetree

Node.js implementation of Sidetree.

Apache-2.0
Latest version published 2 years ago

Package Health Score

46 / 100
Full package analysis

Similar packages