Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bedrock-app-identity

Package Overview
Dependencies
Maintainers
5
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bedrock-app-identity - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

5

CHANGELOG.md
# bedrock-app-identity ChangeLog
## 1.1.0 - 2021-11-18
- Use `generateSecretKeySeed()` and `decodeSecretKeySeed()` from bnid for
creating and decoding secret key pair seeds.
## 1.0.0 - 2021-09-02
- See git history for changes.

41

lib/main.js

@@ -5,3 +5,3 @@ /*!

import bedrock from 'bedrock';
import {decode} from 'base58-universal';
import {decodeSecretKeySeed} from 'bnid';
import {driver} from '@digitalbazaar/did-method-key';

@@ -15,9 +15,2 @@ import logger from './logger.js';

// multibase base58-btc header
const MULTIBASE_BASE58BTC_HEADER = 'z';
// multihash identity function cdoe
const MULTIHASH_IDENTITY_FUNCTION_CODE = 0x00;
// seed byte size
const SEED_BYTE_SIZE = 32;
let APPLICATION_IDENTITY;

@@ -130,5 +123,5 @@ const SERVICE_IDENTITIES = new Map();

// convert multibase seed to Uint8Array
const seed = _decodeMultibaseSeed({seedMultibase});
const seed = decodeSecretKeySeed({secretKeySeed: seedMultibase});
// inialize key after bedrock configuration stage is complete
// initialize key after bedrock configuration stage is complete
const didKey = await didKeyDriver.generate({seed});

@@ -158,29 +151,1 @@

}
function _decodeMultibaseSeed({seedMultibase}) {
const prefix = seedMultibase[0];
if(prefix !== MULTIBASE_BASE58BTC_HEADER) {
throw new Error('Unsupported multibase encoding.');
}
const data = seedMultibase.substring(1);
// <varint hash fn code> <varint digest size in bytes> <hash fn output>
// <identity function> <32> <seed bytes>
const seedMultihash = decode(data);
// <varint hash fn code>: identity function
const [hashFnCode] = seedMultihash.slice(0, 1);
if(hashFnCode !== MULTIHASH_IDENTITY_FUNCTION_CODE) {
throw new Error('Invalid multihash function code.');
}
// <varint digest size in bytes>: 32
const [digestSize] = seedMultihash.slice(1, 2);
if(digestSize !== SEED_BYTE_SIZE) {
throw new Error('Invalid digest size.');
}
// <hash fn output>: seed bytes
const seedBytes = seedMultihash.slice(2, seedMultihash.length);
if(seedBytes.byteLength !== SEED_BYTE_SIZE) {
throw new Error('Invalid digest.');
}
return seedBytes;
}
{
"name": "bedrock-app-identity",
"version": "1.0.0",
"version": "1.1.0",
"description": "Bedrock HTTP API",

@@ -28,3 +28,3 @@ "main": "./lib",

"@digitalbazaar/did-method-key": "^2.0.0",
"base58-universal": "^1.0.0",
"bnid": "^2.1.0",
"esm": "^3.2.25"

@@ -39,3 +39,2 @@ },

"devDependencies": {
"bnid": "^2.0.0",
"eslint": "^7.14.0",

@@ -42,0 +41,0 @@ "eslint-config-digitalbazaar": "^2.6.1"

@@ -6,45 +6,15 @@ /*!

const {encode} = require('base58-universal');
const {driver} = require('@digitalbazaar/did-method-key');
const {IdGenerator} = require('bnid');
const {generateSecretKeySeed, decodeSecretKeySeed} = require('bnid');
// multibase base58-btc header
const MULTIBASE_BASE58BTC_HEADER = 'z';
// multihash identity function cdoe
const MULTIHASH_IDENTITY_FUNCTION_CODE = 0x00;
// seed byte size
const SEED_BYTE_SIZE = 32;
const SEED_BITS_SIZE = SEED_BYTE_SIZE * 8;
const didKeyDriver = driver();
// 256 bit (32 byte) random id generator
const generator = new IdGenerator({
bitLength: SEED_BITS_SIZE
});
(async () => {
// generate a random seed
const seedBytes = await generator.generate();
if(seedBytes.length !== SEED_BYTE_SIZE) {
throw new Error('Generated seed does not match expected byte size.', {
generatedSize: seedBytes.byteLength,
expectedSize: SEED_BYTE_SIZE
});
}
const secretKeySeed = await generateSecretKeySeed();
const seedBytes = await decodeSecretKeySeed({secretKeySeed});
const didKey = await didKeyDriver.generate({seed: seedBytes});
// <varint hash fn code> <varint digest size in bytes> <hash fn output>
// <identity function> <32> <seed bytes>
const seedMultihash = new Uint8Array(2 + SEED_BYTE_SIZE);
// <varint hash fn code>: identity function
seedMultihash.set([MULTIHASH_IDENTITY_FUNCTION_CODE]);
// <varint digest size in bytes>: 32
seedMultihash.set([SEED_BYTE_SIZE], 1);
// <hash fn output>: seed bytes
seedMultihash.set(seedBytes, 2);
const seedMultibase = MULTIBASE_BASE58BTC_HEADER + encode(seedMultihash);
const didKey = await didKeyDriver.generate({seed: seedBytes});
console.log('PUBLIC DID', didKey.didDocument.id);
console.log(`SECRET seedMultibase: ${seedMultibase}`);
console.log(`SECRET seedMultibase: ${secretKeySeed}`);
})();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc