mirror of
https://github.com/mii443/did-web-on-gh-pages.git
synced 2025-12-03 11:08:20 +00:00
generate did document
This commit is contained in:
18
docs/.well-known/did.json
Normal file
18
docs/.well-known/did.json
Normal file
@@ -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"
|
||||
]
|
||||
}
|
||||
20
src/index.js
20
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();
|
||||
Reference in New Issue
Block a user