From ad49955400f5966e12d2ed2b3f1d4f5fbd789c83 Mon Sep 17 00:00:00 2001 From: Ryosuke Abe Date: Tue, 5 Apr 2022 17:29:30 +0900 Subject: [PATCH] generate did document --- docs/.well-known/did.json | 18 ++++++++++++++++++ src/index.js | 20 ++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 docs/.well-known/did.json diff --git a/docs/.well-known/did.json b/docs/.well-known/did.json new file mode 100644 index 0000000..cde3053 --- /dev/null +++ b/docs/.well-known/did.json @@ -0,0 +1,18 @@ +{ + "@context": "https://www.w3.org/ns/did/v1", + "id": "did:web:chike.xyz:id-web-on-gh-pages", + "verificationMethod": [ + { + "id": "did:web:chike.xyz:id-web-on-gh-pages#key1", + "type": "Ed25519VerificationKey2018", + "controller": "did:web:chike.xyz:id-web-on-gh-pages", + "publicKeyBase58": "251vtfUrTJkH5Zaq1Pp39FuKxn1K8AyDimoRgnqikiE34" + } + ], + "authentication": [ + "did:web:chike.xyz:id-web-on-gh-pages#key1" + ], + "assertionMethod": [ + "did:web:chike.xyz:id-web-on-gh-pages#key1" + ] +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 3e96cf6..799fad3 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,23 @@ const { randomBytes } = require('crypto'); const secp256k1 = require('secp256k1'); const bs58 = require('bs58'); +const fs = require('fs'); // Setting const DOMAIN = 'chike.xyz'; const GH_PROJECT = 'id-web-on-gh-pages'; -// MAIN +// Templates const DID = `did:web:${DOMAIN}:${GH_PROJECT}`; +const DID_DOCUMENT_FRAME = { + "@context": "https://www.w3.org/ns/did/v1", + "id": '', + "verificationMethod": [], + "authentication": [], + "assertionMethod": [], +} + const main = async () => { // generate privKey let privKey @@ -25,8 +34,15 @@ const main = async () => { "controller": `${DID}`, "publicKeyBase58": bs58.encode(pubKey) } + const didDocument = DID_DOCUMENT_FRAME; + didDocument.id = key.controller; + didDocument.verificationMethod = [key]; + didDocument.authentication = [key.id]; + didDocument.assertionMethod = [key.id]; - console.log(JSON.stringify(key, null, 2)); + console.log('===GENERATED DID DOCUMENT==='); + console.log(JSON.stringify(didDocument, null, 2)); + fs.writeFileSync('./docs/.well-known/did.json', JSON.stringify(didDocument, null, 2)); }; main(); \ No newline at end of file