Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NetworkID from DIDs + Reorganize 'dist' structure #18

Merged
merged 5 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. */
Copy link
Author

@youngjoon-lee youngjoon-lee Sep 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the dist/ like:

dist/index.js
dist/...

Previously, it was:

dist/src/index.js
dist/src/...
dist/test/...

which is not compatible with our package.json. Also, we don't need to transcompile test/**/*.ts.

Reference: https://github.com/terra-project/terra.js/blob/41ffbd4f9a8d827f8df0764c98327ca8101e455e/tsconfig.json#L20

// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
"removeComments": true, /* Do not emit comments to output. */
Expand Down