bedrock-app-identity
Advanced tools
Comparing version 1.0.0 to 1.1.0
# 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. |
@@ -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}`); | ||
})(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
17193
239
1
+ Addedbnid@^2.1.0
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedbnid@2.1.0(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcliui@6.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@2.0.0(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@15.4.1(transitive)
+ Addedyargs-parser@18.1.3(transitive)
- Removedbase58-universal@^1.0.0