Skip to content

Commit

Permalink
Remove NetworkID from DIDs + Reorganize 'dist' structure (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youngjoon Lee authored Oct 5, 2020
1 parent 8c1d12e commit ac515b2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions example/did.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import panaceajs from '../dist/src/index.js';
import panaceajs from '../dist/index.js';

const txBroadcastMode = 'block';
const chainId = 'testing';
Expand Down Expand Up @@ -33,7 +33,7 @@ async function createDID(account, keystore) {

const didPrivKey = panaceajs.crypto.getPrivateKeyFromKeyStore(keystore, didKeyPasswd);
const didPubKey = panaceajs.crypto.getPublicKeyFromPrivateKey(didPrivKey);
const didDoc = panaceajs.utils.did.generateDIDDocument('testnet', 'key1', didPubKey);
const didDoc = panaceajs.utils.did.generateDIDDocument('key1', didPubKey);
const sig = panaceajs.utils.did.sign(didDoc, panaceajs.Message.DID.InitialSequence, didPrivKey);

const msg = new panaceajs.Message.DID.CreateDID({
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@medibloc/panacea-js",
"version": "1.2.11",
"version": "1.3.0",
"description": "JavaScript library for MediBloc written in Typescript",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
38 changes: 19 additions & 19 deletions src/config/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,42 @@ export const SIMPLE_TX = {

export const SIMPLE_DID_DOC = new DIDDocument(
['https://www.w3.org/ns/did/v1'],
'did:panacea:testnet:LfBBguz7sBppPUrAsvTzd',
'did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm',
[
new DIDVerificationMethod(
'did:panacea:testnet:LfBBguz7sBppPUrAsvTzd#key1',
'did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm#key1',
'Secp256k1VerificationKey2018',
'did:panacea:testnet:LfBBguz7sBppPUrAsvTzd',
'did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm',
'pHtDjG9XTs1muhzno6qKor3UiK8v994zDoVHLGgT9R8D',
),
],
[
new DIDAuthentication('did:panacea:testnet:LfBBguz7sBppPUrAsvTzd#key2'),
new DIDAuthentication('did:panacea:testnet:LfBBguz7sBppPUrAsvTzd#key1', new DIDVerificationMethod(
'did:panacea:testnet:LfBBguz7sBppPUrAsvTzd#key1',
new DIDAuthentication('did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm#key2'),
new DIDAuthentication('did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm#key1', new DIDVerificationMethod(
'did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm#key1',
'Secp256k1VerificationKey2018',
'did:panacea:testnet:LfBBguz7sBppPUrAsvTzd',
'did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm',
'pHtDjG9XTs1muhzno6qKor3UiK8v994zDoVHLGgT9R8D',
)),
],
);
export const SIMPLE_DID_DOC_PLAIN = {
'@context': "https://www.w3.org/ns/did/v1",
id: "did:panacea:testnet:LfBBguz7sBppPUrAsvTzd",
id: "did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm",
verificationMethod: [
{
"id": "did:panacea:testnet:LfBBguz7sBppPUrAsvTzd#key1",
"id": "did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm#key1",
"type": "Secp256k1VerificationKey2018",
"controller": "did:panacea:testnet:LfBBguz7sBppPUrAsvTzd",
"controller": "did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm",
"publicKeyBase58": "pHtDjG9XTs1muhzno6qKor3UiK8v994zDoVHLGgT9R8D"
}
],
authentication: [
"did:panacea:testnet:LfBBguz7sBppPUrAsvTzd#key2",
"did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm#key2",
{
"id": "did:panacea:testnet:LfBBguz7sBppPUrAsvTzd#key1",
"id": "did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm#key1",
"type": "Secp256k1VerificationKey2018",
"controller": "did:panacea:testnet:LfBBguz7sBppPUrAsvTzd",
"controller": "did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm",
"publicKeyBase58": "pHtDjG9XTs1muhzno6qKor3UiK8v994zDoVHLGgT9R8D"
}
]
Expand Down Expand Up @@ -114,22 +114,22 @@ export const MESSAGE = {
},
DID: {
CREATE_DID: {
did: 'did:panacea:testnet:LfBBguz7sBppPUrAsvTzd',
did: 'did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm',
document: SIMPLE_DID_DOC,
verificationMethodId: 'did:panacea:mainnet:DnreD8QqXAQaEW9DwC16Wh#key1',
verificationMethodId: 'did:panacea:DnreD8QqXAQaEW9DwC16Wh#key1',
signature: 'asdfkljaslkfdjdlsk',
fromAddress: ACCOUNT.address,
},
UPDATE_DID: {
did: 'did:panacea:testnet:LfBBguz7sBppPUrAsvTzd',
did: 'did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm',
document: SIMPLE_DID_DOC,
verificationMethodId: 'did:panacea:mainnet:DnreD8QqXAQaEW9DwC16Wh#key1',
verificationMethodId: 'did:panacea:DnreD8QqXAQaEW9DwC16Wh#key1',
signature: 'asdfkljaslkfdjdlsk',
fromAddress: ACCOUNT.address,
},
DEACTIVATE_DID: {
did: 'did:panacea:testnet:LfBBguz7sBppPUrAsvTzd',
verificationMethodId: 'did:panacea:testnet:LfBBguz7sBppPUrAsvTzd#key1',
did: 'did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm',
verificationMethodId: 'did:panacea:7Prd74ry1Uct87nZqL3ny7aR7Cg46JamVbJgk8azVgUm#key1',
signature: 'asdfkljaslkfdjdlsk',
fromAddress: ACCOUNT.address,
},
Expand Down
10 changes: 5 additions & 5 deletions src/utils/did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ const bs58 = require('bs58');
const didMethod = 'panacea';
const keyType = 'Secp256k1VerificationKey2018';

function generateDID(networkID: string, pubKeyBuf: Buffer) {
const idStr = bs58.encode(pubKeyBuf.subarray(0, 16));
return `did:${didMethod}:${networkID}:${idStr}`;
function generateDID(pubKeyHex: string) {
const idStr = bs58.encode(Buffer.from(sha256(pubKeyHex), 'hex'));
return `did:${didMethod}:${idStr}`;
}

export const generateDIDDocument = (networkID: string, keyIDSuffix: string, pubKeyHex: string): DIDDocument => {
export const generateDIDDocument = (keyIDSuffix: string, pubKeyHex: string): DIDDocument => {
const pubKeyBuf = Buffer.from(pubKeyHex, 'hex');

const contexts = ['https://www.w3.org/ns/did/v1'];
const did = generateDID(networkID, pubKeyBuf);
const did = generateDID(pubKeyHex);
const didPubKey = new DIDVerificationMethod(`${did}#${keyIDSuffix}`, keyType, did, bs58.encode(pubKeyBuf));
const auth = new DIDAuthentication(didPubKey.id)

Expand Down
2 changes: 1 addition & 1 deletion test/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import config, { test } from '../../src/config';
import { PARAM } from '../../src/config/default';
import { Client } from '../../src';

const privFnRewire = rewire('../../dist/src/client/Client');
const privFnRewire = rewire('../../dist/client/Client');
const injectParams = privFnRewire.__get__('injectParams'); // eslint-disable-line no-underscore-dangle

describe('client', () => {
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["src", "test"],
"include": ["src"],
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

Expand All @@ -15,8 +15,8 @@
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "dist", /* Redirect output structure to the directory. */
"rootDir": ".", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"outDir": "dist", /* Redirect output structure to the directory. */
"rootDir": "src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
"removeComments": true, /* Do not emit comments to output. */
Expand Down

0 comments on commit ac515b2

Please sign in to comment.