From bb19725ee9a0ef9097fa729a1af967c1b0a49f2e Mon Sep 17 00:00:00 2001 From: Youngjoon Lee Date: Wed, 30 Sep 2020 08:28:56 +0900 Subject: [PATCH 1/5] Changes for the new DID format: No network ID --- example/did.js | 2 +- src/config/test.ts | 38 +++++++++++++++++++------------------- src/utils/did.ts | 10 +++++----- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/example/did.js b/example/did.js index df57a18..2eccc44 100644 --- a/example/did.js +++ b/example/did.js @@ -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({ diff --git a/src/config/test.ts b/src/config/test.ts index 86ca07c..3188056 100644 --- a/src/config/test.ts +++ b/src/config/test.ts @@ -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" } ] @@ -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, }, diff --git a/src/utils/did.ts b/src/utils/did.ts index 8a0ef2d..11dd55e 100644 --- a/src/utils/did.ts +++ b/src/utils/did.ts @@ -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) From e47d6021492d882d4c15dc2c3804064a8fa68604 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee Date: Wed, 30 Sep 2020 09:04:50 +0900 Subject: [PATCH 2/5] Bump the version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ce9f8e7..e795de8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@medibloc/panacea-js", - "version": "1.2.11", + "version": "1.3.0-test", "description": "JavaScript library for MediBloc written in Typescript", "main": "dist/index.js", "typings": "dist/index.d.ts", From acc8c8f6cccae558c7faaf9ce1b483194b32a13f Mon Sep 17 00:00:00 2001 From: Youngjoon Lee Date: Wed, 30 Sep 2020 09:36:34 +0900 Subject: [PATCH 3/5] Reorganize package structure --- example/did.js | 2 +- package-lock.json | 4 ++-- package.json | 2 +- test/client/Client.ts | 2 +- tsconfig.json | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/example/did.js b/example/did.js index 2eccc44..0138a38 100644 --- a/example/did.js +++ b/example/did.js @@ -1,4 +1,4 @@ -import panaceajs from '../dist/src/index.js'; +import panaceajs from '../dist/index.js'; const txBroadcastMode = 'block'; const chainId = 'testing'; diff --git a/package-lock.json b/package-lock.json index 2da38f4..011200c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "@medibloc/panacea-js", - "version": "1.2.11", + "name": "@youngjoon-lee/panacea-js", + "version": "1.3.0-test", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e795de8..7aa24d6 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@medibloc/panacea-js", + "name": "@youngjoon-lee/panacea-js", "version": "1.3.0-test", "description": "JavaScript library for MediBloc written in Typescript", "main": "dist/index.js", diff --git a/test/client/Client.ts b/test/client/Client.ts index 3b557f4..5aefc78 100644 --- a/test/client/Client.ts +++ b/test/client/Client.ts @@ -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', () => { diff --git a/tsconfig.json b/tsconfig.json index 41115a4..0cf7a4d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["src", "test"], + "include": ["src"], "compilerOptions": { /* Visit https://aka.ms/tsconfig.json to read more about this file */ @@ -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. */ From 9559510c223f37187601b914e1d507ebb524be76 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee Date: Wed, 30 Sep 2020 09:40:05 +0900 Subject: [PATCH 4/5] Revert the package name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7aa24d6..e795de8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@youngjoon-lee/panacea-js", + "name": "@medibloc/panacea-js", "version": "1.3.0-test", "description": "JavaScript library for MediBloc written in Typescript", "main": "dist/index.js", From 24a1dd904016c0a4db01fb6abee3de1502075a31 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee Date: Wed, 30 Sep 2020 10:09:56 +0900 Subject: [PATCH 5/5] version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 011200c..3697ff0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "@youngjoon-lee/panacea-js", - "version": "1.3.0-test", + "name": "@medibloc/panacea-js", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e795de8..7ece8f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@medibloc/panacea-js", - "version": "1.3.0-test", + "version": "1.3.0", "description": "JavaScript library for MediBloc written in Typescript", "main": "dist/index.js", "typings": "dist/index.d.ts",