diff --git a/build/libs/w3cache/v1/index.d.ts.map b/build/libs/w3cache/v1/index.d.ts.map index 164945e..589fb99 100644 --- a/build/libs/w3cache/v1/index.d.ts.map +++ b/build/libs/w3cache/v1/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../libs/w3cache/v1/index.ts"],"names":[],"mappings":";AA4CA,wBAUE"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../libs/w3cache/v1/index.ts"],"names":[],"mappings":";AAuCA,wBAUE"} diff --git a/build/libs/w3cache/v1/index.js b/build/libs/w3cache/v1/index.js index be7f753..53fcac9 100644 --- a/build/libs/w3cache/v1/index.js +++ b/build/libs/w3cache/v1/index.js @@ -20,6 +20,7 @@ const jsonld_1 = __importDefault(require("jsonld")); const vc_data_integrety_json_1 = __importDefault(require("./vc-data-integrety.json")); const lds_ecdsa_secp256k1_recovery2020_json_1 = __importDefault(require("./lds-ecdsa-secp256k1-recovery2020.json")); const schema_org_json_1 = __importDefault(require("./schema_org.json")); +const x25519_key_agreement_2020_v1_json_1 = __importDefault(require("./x25519-key-agreement-2020-v1.json")); // Ref: https://github.com/digitalbazaar/jsonld.js/#custom-document-loader let nodeDocumentLoader; if (typeof window === 'undefined') { @@ -37,6 +38,7 @@ const CONTEXTS = Object.freeze({ "https://w3c.github.io/vc-data-integrity/vocab/security/vocabulary.jsonld": Object.assign({}, vc_data_integrety_json_1.default), "https://w3id.org/security/suites/secp256k1recovery-2020/v2": Object.assign({}, lds_ecdsa_secp256k1_recovery2020_json_1.default), "https://schema.org": Object.assign({}, schema_org_json_1.default), + "https://digitalbazaar.github.io/x25519-key-agreement-2020-context/contexts/x25519-key-agreement-2020-v1.jsonld": Object.assign({}, x25519_key_agreement_2020_v1_json_1.default), "https://identity.foundation/.well-known/did-configuration/v1": Object.assign({}, did_wellknown_json_1.default) }); exports.default = (url, options) => __awaiter(void 0, void 0, void 0, function* () { diff --git a/build/libs/w3cache/v1/x25519-key-agreement-2020-v1.json b/build/libs/w3cache/v1/x25519-key-agreement-2020-v1.json new file mode 100644 index 0000000..9d9ffe3 --- /dev/null +++ b/build/libs/w3cache/v1/x25519-key-agreement-2020-v1.json @@ -0,0 +1,28 @@ +{ + "@context": { + "id": "@id", + "type": "@type", + "@protected": true, + "X25519KeyAgreementKey2020": { + "@id": "https://w3id.org/security#X25519KeyAgreementKey2020", + "@context": { + "@protected": true, + "id": "@id", + "type": "@type", + "controller": { + "@id": "https://w3id.org/security#controller", + "@type": "@id" + }, + "revoked": { + "@id": "https://w3id.org/security#revoked", + "@type": "http://www.w3.org/2001/XMLSchema#dateTime" + }, + "publicKeyMultibase": { + "@id": "https://w3id.org/security#publicKeyMultibase", + "@type": "https://w3id.org/security#multibase" + }, + "blockchainAccountId": "https://w3id.org/security#blockchainAccountId" + } + } + } +} diff --git a/build/src/constants.d.ts b/build/src/constants.d.ts index caed137..9a5f718 100644 --- a/build/src/constants.d.ts +++ b/build/src/constants.d.ts @@ -31,6 +31,7 @@ export declare const DID_Ed25519VerificationKey2020: { METHOD: string; NAMESPACE: string; DID_BASE_CONTEXT: string; + DID_KEYAGREEMENT_CONTEXT: string; VERIFICATION_METHOD_TYPE: string; BLOCKCHAINACCOUNTID_CONTEXT: string; }; @@ -40,6 +41,7 @@ export declare const DID_EcdsaSecp256k1RecoveryMethod2020: { METHOD: string; NAMESPACE: string; DID_BASE_CONTEXT: string; + DID_KEYAGREEMENT_CONTEXT: string; BLOCKCHAINACCOUNTID_CONTEXT: string; VERIFICATION_METHOD_TYPE: string; }; diff --git a/build/src/constants.d.ts.map b/build/src/constants.d.ts.map index d19e3d2..be93795 100644 --- a/build/src/constants.d.ts.map +++ b/build/src/constants.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,qBAAqB,oCAAoC,CAAC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S,QAAQ,CAAC;AAC/B,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,eAAe,SAAS,CAAC;AACtC,eAAO,MAAM,WAAW,WAAW,CAAC;AACpC,eAAO,MAAM,WAAW,SAAS,CAAC"} \ No newline at end of file diff --git a/build/src/constants.js b/build/src/constants.js index b0c732a..3313cb6 100644 --- a/build/src/constants.js +++ b/build/src/constants.js @@ -38,6 +38,7 @@ exports.DID_Ed25519VerificationKey2020 = { METHOD: 'hid', NAMESPACE: 'testnet', DID_BASE_CONTEXT: 'https://www.w3.org/ns/did/v1', + DID_KEYAGREEMENT_CONTEXT: "https://digitalbazaar.github.io/x25519-key-agreement-2020-context/contexts/x25519-key-agreement-2020-v1.jsonld", VERIFICATION_METHOD_TYPE: 'Ed25519VerificationKey2020', BLOCKCHAINACCOUNTID_CONTEXT: 'https://w3c.github.io/vc-data-integrity/vocab/security/vocabulary.jsonld', }; @@ -47,6 +48,7 @@ exports.DID_EcdsaSecp256k1RecoveryMethod2020 = { METHOD: 'hid', NAMESPACE: 'testnet', DID_BASE_CONTEXT: 'https://www.w3.org/ns/did/v1', + DID_KEYAGREEMENT_CONTEXT: "https://github.com/hypersign-protocol/hid-ssi-js-sdk/blob/develop/libs/w3cache/v1/X25519KeyAgreementKeyEIP5630.json", BLOCKCHAINACCOUNTID_CONTEXT: 'https://w3c.github.io/vc-data-integrity/vocab/security/vocabulary.jsonld', VERIFICATION_METHOD_TYPE: 'EcdsaSecp256k1RecoveryMethod2020', }; diff --git a/build/src/did/IDID.d.ts b/build/src/did/IDID.d.ts index 59abc6e..2d1c5a2 100644 --- a/build/src/did/IDID.d.ts +++ b/build/src/did/IDID.d.ts @@ -20,7 +20,9 @@ export declare enum IVerificationRelationships { export declare enum IKeyType { Ed25519VerificationKey2020 = "Ed25519VerificationKey2020", EcdsaSecp256k1VerificationKey2019 = "EcdsaSecp256k1VerificationKey2019", - EcdsaSecp256k1RecoveryMethod2020 = "EcdsaSecp256k1RecoveryMethod2020" + EcdsaSecp256k1RecoveryMethod2020 = "EcdsaSecp256k1RecoveryMethod2020", + X25519KeyAgreementKey2020 = "X25519KeyAgreementKey2020", + X25519KeyAgreementKeyEIP5630 = "X25519KeyAgreementKeyEIP5630" } export declare enum IClientSpec { 'eth-personalSign' = "eth-personalSign", diff --git a/build/src/did/IDID.d.ts.map b/build/src/did/IDID.d.ts.map index f4c4e34..ab2fc14 100644 --- a/build/src/did/IDID.d.ts.map +++ b/build/src/did/IDID.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IDID.d.ts","sourceRoot":"","sources":["../../../src/did/IDID.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACjH,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,oBAAY,0BAA0B;IACpC,cAAc,mBAAmB;IACjC,eAAe,oBAAoB;IACnC,YAAY,iBAAiB;IAC7B,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;CAC9C;AAED,oBAAY,QAAQ;IAClB,0BAA0B,+BAA+B;IACzD,iCAAiC,sCAAsC;IACvE,gCAAgC,qCAAqC;CACtE;AAED,oBAAY,WAAW;IACrB,kBAAkB,qBAAqB;IACvC,eAAe,kBAAkB;CAClC;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,UAAU,CAAC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C;CACpB"} \ No newline at end of file diff --git a/build/src/did/IDID.js b/build/src/did/IDID.js index 6a48a24..d0fea09 100644 --- a/build/src/did/IDID.js +++ b/build/src/did/IDID.js @@ -19,6 +19,8 @@ var IKeyType; IKeyType["Ed25519VerificationKey2020"] = "Ed25519VerificationKey2020"; IKeyType["EcdsaSecp256k1VerificationKey2019"] = "EcdsaSecp256k1VerificationKey2019"; IKeyType["EcdsaSecp256k1RecoveryMethod2020"] = "EcdsaSecp256k1RecoveryMethod2020"; + IKeyType["X25519KeyAgreementKey2020"] = "X25519KeyAgreementKey2020"; + IKeyType["X25519KeyAgreementKeyEIP5630"] = "X25519KeyAgreementKeyEIP5630"; })(IKeyType = exports.IKeyType || (exports.IKeyType = {})); var IClientSpec; (function (IClientSpec) { diff --git a/build/src/did/did.d.ts b/build/src/did/did.d.ts index 47efff4..be4ceb5 100644 --- a/build/src/did/did.d.ts +++ b/build/src/did/did.d.ts @@ -1,6 +1,6 @@ import { Did, SignInfo } from '../../libs/generated/ssi/did'; import Web3 from 'web3'; -import { IDID, IDIDResolve, ISignedDIDDocument, IClientSpec, IVerificationRelationships } from './IDID'; +import { IDID, IDIDResolve, ISignedDIDDocument, IKeyType, IClientSpec, IVerificationRelationships } from './IDID'; import { OfflineSigner } from '@cosmjs/proto-signing'; /** Class representing HypersignDID */ export default class HypersignDID implements IDID { @@ -189,5 +189,14 @@ export default class HypersignDID implements IDID { didDocument: Did; signature: string; }>; + addVerificationMethod(params: { + did?: string; + didDocument?: Did; + type: IKeyType; + id?: string; + controller?: string; + publicKeyMultibase?: string; + blockchainAccountId?: string; + }): Promise; } //# sourceMappingURL=did.d.ts.map \ No newline at end of file diff --git a/build/src/did/did.d.ts.map b/build/src/did/did.d.ts.map index 88fa30f..60fee0b 100644 --- a/build/src/did/did.d.ts.map +++ b/build/src/did/did.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../../../src/did/did.ts"],"names":[],"mappings":"AAWA,OAA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,CAAC;KAClB,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,GAAG,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IA8DvC,qBAAqB,CAAC,MAAM,EAAE;QACzC,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,GAAG,CAAC;QAClB,IAAI,EAAE,QAAQ,CAAC;QACf,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,GAAG,OAAO,CAAC,GAAG,CAAC;CAwGjB"} \ No newline at end of file diff --git a/build/src/did/did.js b/build/src/did/did.js index 3ae1977..69efa59 100644 --- a/build/src/did/did.js +++ b/build/src/did/did.js @@ -195,7 +195,6 @@ class HypersignDID { IDID_1.IVerificationRelationships.authentication, IDID_1.IVerificationRelationships.capabilityDelegation, IDID_1.IVerificationRelationships.capabilityInvocation, - IDID_1.IVerificationRelationships.keyAgreement, ]; if (verificationRelationships && verificationRelationships.length > 0) { const set1 = new Set(vR); @@ -269,6 +268,9 @@ class HypersignDID { return __awaiter(this, void 0, void 0, function* () { let verificationRelationships = []; if (params.verificationRelationships && params.verificationRelationships.length > 0) { + if (params.verificationRelationships.includes(IDID_1.IVerificationRelationships.keyAgreement)) { + throw new Error('HID-SSI-SDK:: Error: keyAgreement is not allowed in verificationRelationships'); + } verificationRelationships = this._filterVerificationRelationships(params.verificationRelationships); } else { @@ -603,6 +605,9 @@ class HypersignDID { let didDoc; let verificationRelationships = []; if (params.verificationRelationships && params.verificationRelationships.length > 0) { + if (params.verificationRelationships.includes(IDID_1.IVerificationRelationships.keyAgreement)) { + throw new Error('HID-SSI-SDK:: Error: keyAgreement is not allowed in verificationRelationships'); + } verificationRelationships = this._filterVerificationRelationships(params.verificationRelationships); } else { @@ -870,5 +875,99 @@ class HypersignDID { } }); } + addVerificationMethod(params) { + var _a, _b, _c; + return __awaiter(this, void 0, void 0, function* () { + let resolvedDidDoc; + if (!params.did && (!params.didDocument || Object.keys(params.didDocument).length === 0)) { + throw new Error('HID-SSI_SDK:: Error: params.did or params.didDocument is required to addVerificationMethod'); + } + if (!params.type) { + throw new Error('HID-SSI-SDK:: Error: params.type is required to addVerificationMethod'); + } + const { type } = params; + if (!(type in IDID_1.IKeyType)) { + throw new Error('HID-SSI-SDK:: Error: params.type is invalid'); + } + try { + if (params.did) { + if (!this.didrpc) { + throw new Error('HID-SSI-SDK:: Error: HID-SSI-SDK:: Error: HypersignDID class is not instantiated with Offlinesigner or have not been initilized'); + } + resolvedDidDoc = yield this.didrpc.resolveDID(params.did); + if (!resolvedDidDoc.didDocument) { + if (!params.didDocument) { + throw new Error('HID-SSI_SDK:: Error: can not able to resolve did please send didDocument'); + } + } + } + else if (params.didDocument) { + resolvedDidDoc = {}; + resolvedDidDoc.didDocument = params.didDocument; + } + else { + throw new Error('HID-SSI-SDK:: Error: params.did or params.didDocument is required to addVerificationMethod'); + } + } + catch (e) { + throw new Error(`HID-SSI-SDK:: Error: could not resolve did ${params.did}`); + } + if (type === IDID_1.IKeyType.EcdsaSecp256k1RecoveryMethod2020 && + (!params.blockchainAccountId || params.blockchainAccountId.trim() === '')) { + throw new Error(`HID-SSI-SDK:: Error: params.blockchainAccountId is required for keyType ${params.type}`); + } + if (type === IDID_1.IKeyType.EcdsaSecp256k1RecoveryMethod2020 && (!params.id || params.id.trim() === '')) { + throw new Error(`HID-SSI-SDK:: Error: params.id is required for keyType ${params.type}`); + } + if (type === IDID_1.IKeyType.EcdsaSecp256k1VerificationKey2019 && + (!params.blockchainAccountId || + params.blockchainAccountId.trim() === '' || + !params.publicKeyMultibase || + params.publicKeyMultibase.trim() === '')) { + throw new Error(`HID-SSI-SDK:: Error: params.blockchainAccountId and params.publicKeyMultibase is required for keyType ${params.type}`); + } + if ((type === IDID_1.IKeyType.Ed25519VerificationKey2020 || + type === IDID_1.IKeyType.X25519KeyAgreementKey2020 || + type === IDID_1.IKeyType.X25519KeyAgreementKeyEIP5630) && + !params.publicKeyMultibase) { + throw new Error('HID-SSI-SDK:: Error: params.publicKeyMultibase is required to addVerificationMethod'); + } + const verificationMethod = {}; + const { didDocument } = resolvedDidDoc; + if (params.id) { + const checkIfVmIdExists = didDocument.verificationMethod.some((vm) => vm.id === params.id); + if (checkIfVmIdExists) { + throw new Error(`HID-SSI-SDK:: Error: verificationMethod ${params.id} already exists`); + } + } + const VMLength = didDocument.verificationMethod.length; + verificationMethod['id'] = (_a = params === null || params === void 0 ? void 0 : params.id) !== null && _a !== void 0 ? _a : `${didDocument.id}#key-${VMLength + 1}`; + //verificationMethod['id'] = params?.id ?? `${didDocument.id}#${params.publicKeyMultibase}`; + verificationMethod['type'] = type; + verificationMethod['controller'] = didDocument.id; + if (type !== IDID_1.IKeyType.EcdsaSecp256k1RecoveryMethod2020) { + verificationMethod['publicKeyMultibase'] = (_b = params === null || params === void 0 ? void 0 : params.publicKeyMultibase) !== null && _b !== void 0 ? _b : ''; + } + verificationMethod['blockchainAccountId'] = (_c = params === null || params === void 0 ? void 0 : params.blockchainAccountId) !== null && _c !== void 0 ? _c : ''; + didDocument.verificationMethod.push(verificationMethod); + if (verificationMethod['type'] === IDID_1.IKeyType.X25519KeyAgreementKey2020 || + verificationMethod['type'] === IDID_1.IKeyType.X25519KeyAgreementKeyEIP5630) { + didDocument.keyAgreement.push(verificationMethod['id']); + } + else { + didDocument.authentication.push(verificationMethod['id']); + didDocument.assertionMethod.push(verificationMethod['id']); + didDocument.capabilityDelegation.push(verificationMethod['id']); + didDocument.capabilityInvocation.push(verificationMethod['id']); + } + if (verificationMethod['type'] === IDID_1.IKeyType.X25519KeyAgreementKey2020) { + didDocument['@context'].push(constant['DID_' + IDID_1.IKeyType.Ed25519VerificationKey2020].DID_KEYAGREEMENT_CONTEXT); + } + if (verificationMethod['type'] === IDID_1.IKeyType.X25519KeyAgreementKeyEIP5630) { + didDocument['@context'].push(constant['DID_' + IDID_1.IKeyType.EcdsaSecp256k1RecoveryMethod2020].DID_KEYAGREEMENT_CONTEXT); + } + return didDocument; + }); + } } exports.default = HypersignDID; diff --git a/build/src/tests/config.d.ts.map b/build/src/tests/config.d.ts.map index b586557..d34e27a 100644 --- a/build/src/tests/config.d.ts.map +++ b/build/src/tests/config.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/tests/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAU,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAExD,eAAO,MAAM,QAAQ,uKACiJ,CAAC;AAEvK,eAAO,MAAM,SAAS;;;;CAIrB,CAAC;AAMF,wBAAgB,iBAAiB,CAAC,CAAC,KAAA,oBAQlC;AAED,eAAO,MAAM,YAAY,qDAmBxB,CAAC"} \ No newline at end of file +{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/tests/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAU,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAExD,eAAO,MAAM,QAAQ,uKACiJ,CAAC;AAQvK,eAAO,MAAM,SAAS;;;;CAIrB,CAAC;AACF,wBAAgB,iBAAiB,CAAC,CAAC,KAAA,oBAQlC;AAED,eAAO,MAAM,YAAY,qDAmBxB,CAAC"} \ No newline at end of file diff --git a/build/src/tests/did.spec.js b/build/src/tests/did.spec.js index 7c8d290..6d935a5 100644 --- a/build/src/tests/did.spec.js +++ b/build/src/tests/did.spec.js @@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const index_1 = require("../index"); +const IDID_1 = require("../did/IDID"); const config_1 = require("./config"); let privateKeyMultibase; let publicKeyMultibase; @@ -25,6 +26,8 @@ let signedDocument; const challenge = '1231231231'; const domain = 'www.adbv.com'; let hypersignSSISDK; +let pubKey; +let didDocToReg; //add mnemonic of wallet that have balance beforeEach(function () { return __awaiter(this, void 0, void 0, function* () { @@ -76,7 +79,6 @@ describe('DID Test scenarios', () => { it('should be able to generate didDocument', function () { return __awaiter(this, void 0, void 0, function* () { didDocument = yield hypersignDID.generate({ publicKeyMultibase }); - //console.log(didDocument) didDocId = didDocument['id']; verificationMethodId = didDocument['verificationMethod'][0].id; (0, chai_1.expect)(didDocument).to.be.a('object'); @@ -132,6 +134,33 @@ describe('DID Test scenarios', () => { (0, chai_1.expect)(didDocument['capabilityDelegation']).to.be.a('array').of.length(0); }); }); + it('should be able to generate didDocument with different kp', function () { + return __awaiter(this, void 0, void 0, function* () { + const kp = yield hypersignDID.generateKeys(); + const privateKeyMultibase = kp.privateKeyMultibase; + pubKey = kp.publicKeyMultibase; + didDocToReg = yield hypersignDID.generate({ publicKeyMultibase: pubKey }); + (0, chai_1.expect)(didDocument).to.be.a('object'); + (0, chai_1.should)().exist(didDocument['@context']); + (0, chai_1.should)().exist(didDocument['id']); + (0, chai_1.should)().exist(didDocument['controller']); + (0, chai_1.should)().exist(didDocument['alsoKnownAs']); + (0, chai_1.should)().exist(didDocument['verificationMethod']); + (0, chai_1.expect)(didDocument['verificationMethod'] && + didDocument['authentication'] && + didDocument['assertionMethod'] && + didDocument['keyAgreement'] && + didDocument['capabilityInvocation'] && + didDocument['capabilityDelegation'] && + didDocument['service']).to.be.a('array'); + (0, chai_1.should)().exist(didDocument['authentication']); + (0, chai_1.should)().exist(didDocument['assertionMethod']); + (0, chai_1.should)().exist(didDocument['keyAgreement']); + (0, chai_1.should)().exist(didDocument['capabilityInvocation']); + (0, chai_1.should)().exist(didDocument['capabilityDelegation']); + (0, chai_1.should)().exist(didDocument['service']); + }); + }); it('should be able to generate didDocument with custom id', function () { return __awaiter(this, void 0, void 0, function* () { const methodSpecificId = 'e157620d69d003e12d935c37b8c21baa78d24898398829b39d943d253c006332'; @@ -196,6 +225,163 @@ describe('DID Test scenarios', () => { }); }); }); + describe('#addVerificationMethod() to add verificationMethod in didDocument', function () { + it('should not be able to add verificationMethod as neither did nor didDoc is passed', () => __awaiter(this, void 0, void 0, function* () { + const params = { + didDocument: {}, + type: 'X25519KeyAgreementKey2020', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + (0, chai_1.expect)(function () { + throw err; + }).to.throw(Error, 'HID-SSI_SDK:: Error: params.did or params.didDocument is required to addVerificationMethod'); + }); + })); + it('should not be able to add verificationMethod as type is not passed', () => __awaiter(this, void 0, void 0, function* () { + const params = { + didDocument, + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + (0, chai_1.expect)(function () { + throw err; + }).to.throw(Error, 'HID-SSI-SDK:: Error: params.type is required to addVerificationMethod'); + }); + })); + it('should not be able to add verificationMethod as type passed is invalid', () => __awaiter(this, void 0, void 0, function* () { + const params = { + didDocument, + type: 'dsyifx', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + (0, chai_1.expect)(function () { + throw err; + }).to.throw(Error, 'HID-SSI-SDK:: Error: params.type is invalid'); + }); + })); + it('should not be able to add verificationMethod as params.did is passed but yet not registerd', () => __awaiter(this, void 0, void 0, function* () { + const params = { + did: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY', + type: IDID_1.IKeyType.Ed25519VerificationKey2020, + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + const hypersignDid = new index_1.HypersignDID({ namespace: 'testnet' }); + return hypersignDid.addVerificationMethod(params).catch(function (err) { + (0, chai_1.expect)(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: could not resolve did ${params.did}`); + }); + })); + it('should not be able to add verificationMethod in didDocument as type is EcdsaSecp256k1RecoveryMethod2020 but blockchainAccountId is not passed', () => __awaiter(this, void 0, void 0, function* () { + const params = { + didDocument, + type: 'EcdsaSecp256k1RecoveryMethod2020', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + (0, chai_1.expect)(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: params.blockchainAccountId is required for keyType ${params.type}`); + }); + })); + it('should not be able to add verificationMethod in didDocument as type is EcdsaSecp256k1RecoveryMethod2020 but params.id is not passed', () => __awaiter(this, void 0, void 0, function* () { + const params = { + didDocument, + type: 'EcdsaSecp256k1RecoveryMethod2020', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + blockchainAccountId: 'eip155:1:23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + (0, chai_1.expect)(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: params.id is required for keyType ${params.type}`); + }); + })); + it('should not be able to add verificationMethod in didDocument as type is EcdsaSecp256k1VerificationKey2019 but neither params.blockchainAccountId nor params.publicKeyMultibase is passed', () => __awaiter(this, void 0, void 0, function* () { + const params = { + didDocument, + type: 'EcdsaSecp256k1VerificationKey2019', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + (0, chai_1.expect)(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: params.blockchainAccountId and params.publicKeyMultibase is required for keyType ${params.type}`); + }); + })); + it('should not be able to add verificationMethod in didDocument as type is EcdsaSecp256k1VerificationKey2019 params.publicKeyMultibase is not passed', () => __awaiter(this, void 0, void 0, function* () { + const params = { + didDocument, + type: 'EcdsaSecp256k1VerificationKey2019', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + blockchainAccountId: 'eip155:1:23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + (0, chai_1.expect)(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: params.blockchainAccountId and params.publicKeyMultibase is required for keyType ${params.type}`); + }); + })); + it('should not be able to add verificationMethod in didDocument as type is EcdsaSecp256k1VerificationKey2019 params.blockchainAccountId is not passed', () => __awaiter(this, void 0, void 0, function* () { + const params = { + didDocument, + type: 'EcdsaSecp256k1VerificationKey2019', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + blockchainAccountId: 'eip155:1:23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + (0, chai_1.expect)(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: params.blockchainAccountId and params.publicKeyMultibase is required for keyType ${params.type}`); + }); + })); + it('Should not be able to add verification method to didDocument as it is already exists', () => __awaiter(this, void 0, void 0, function* () { + const params = { + didDocument: didDocument, + type: 'X25519KeyAgreementKey2020', + id: `${didDocument.verificationMethod[0].id}`, + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + (0, chai_1.expect)(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: verificationMethod ${params.id} already exists`); + }); + })); + it('should be able to add verification method in didDocument', () => __awaiter(this, void 0, void 0, function* () { + const params = { + didDocument: didDocument, + type: 'X25519KeyAgreementKey2020', + // id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + const didDoc = JSON.parse(JSON.stringify(didDocument)); + const updatedDidDoc = yield hypersignDID.addVerificationMethod(params); + (0, chai_1.expect)(updatedDidDoc).to.be.a('object'); + (0, chai_1.should)().exist(updatedDidDoc['@context']); + (0, chai_1.should)().exist(updatedDidDoc['id']); + (0, chai_1.should)().exist(updatedDidDoc['controller']); + (0, chai_1.should)().exist(updatedDidDoc['alsoKnownAs']); + (0, chai_1.should)().exist(updatedDidDoc['verificationMethod']); + (0, chai_1.expect)(updatedDidDoc['verificationMethod'] && + updatedDidDoc['authentication'] && + updatedDidDoc['assertionMethod'] && + updatedDidDoc['keyAgreement'] && + updatedDidDoc['capabilityInvocation'] && + updatedDidDoc['capabilityDelegation'] && + updatedDidDoc['service']).to.be.a('array'); + (0, chai_1.should)().exist(updatedDidDoc['authentication']); + (0, chai_1.should)().exist(updatedDidDoc['assertionMethod']); + (0, chai_1.expect)(updatedDidDoc.verificationMethod.length).to.be.greaterThan(didDoc.verificationMethod.length); + })); + }); describe('#register() this is to register did on the blockchain', function () { it('should not able to register did document and throw error as didDocument is not passed or it is empty', function () { return hypersignDID @@ -227,7 +413,6 @@ describe('DID Test scenarios', () => { it('should be able to register didDocument in the blockchain', function () { return __awaiter(this, void 0, void 0, function* () { const result = yield hypersignDID.register({ didDocument, privateKeyMultibase, verificationMethodId }); - //console.log(result) transactionHash = result.transactionHash; (0, chai_1.should)().exist(result.code); (0, chai_1.should)().exist(result.height); @@ -252,7 +437,6 @@ describe('DID Test scenarios', () => { did: didDocId, }; const result = yield hypersignDID.resolve(params); - //console.log(result); (0, chai_1.expect)(result).to.be.a('object'); (0, chai_1.expect)(result.didDocument.id).to.be.equal(didDocId); (0, chai_1.expect)(result.didDocumentMetadata).to.be.a('object'); @@ -306,7 +490,6 @@ describe('DID Test scenarios', () => { verificationMethodId, versionId, }); - //console.log(result); (0, chai_1.should)().exist(result.code); (0, chai_1.should)().exist(result.height); (0, chai_1.should)().exist(result.rawLog); @@ -404,7 +587,6 @@ describe('DID Test scenarios', () => { verificationMethodId, versionId, }); - //console.log(JSON.stringify(result)); (0, chai_1.should)().exist(result.code); (0, chai_1.should)().exist(result.height); (0, chai_1.should)().exist(result.rawLog); @@ -527,7 +709,6 @@ describe('DID Test scenarios', () => { controller, }; signedDocument = yield hypersignDID.sign(params); - //console.log(JSON.stringify(signedDocument)) (0, chai_1.expect)(signedDocument).to.be.a('object'); (0, chai_1.should)().exist(signedDocument['@context']); (0, chai_1.should)().exist(signedDocument['id']); @@ -566,14 +747,12 @@ describe('DID Test scenarios', () => { }); it('should return verification result', function () { return __awaiter(this, void 0, void 0, function* () { - console.log(JSON.stringify(signedDocument, null, 2)); const result = yield hypersignDID.verify({ didDocument: signedDocument, verificationMethodId, challenge, domain, }); - console.log(result); (0, chai_1.expect)(result).to.be.a('object'); (0, chai_1.should)().exist(result); (0, chai_1.should)().exist(result.verified); diff --git a/libs/w3cache/v1/index.ts b/libs/w3cache/v1/index.ts index 79119c0..a87382f 100644 --- a/libs/w3cache/v1/index.ts +++ b/libs/w3cache/v1/index.ts @@ -6,6 +6,7 @@ import jsonld from 'jsonld'; import dataintegrety from './vc-data-integrety.json' import ecdsasecp2020 from './lds-ecdsa-secp256k1-recovery2020.json' import schema_org from './schema_org.json' +import x25519VerificationKey2020 from "./x25519-key-agreement-2020-v1.json" // Ref: https://github.com/digitalbazaar/jsonld.js/#custom-document-loader let nodeDocumentLoader; @@ -37,6 +38,9 @@ const CONTEXTS = Object.freeze({ "https://schema.org": { ...schema_org }, + "https://digitalbazaar.github.io/x25519-key-agreement-2020-context/contexts/x25519-key-agreement-2020-v1.jsonld":{ + ...x25519VerificationKey2020 + }, "https://identity.foundation/.well-known/did-configuration/v1": { ...wellknown } diff --git a/libs/w3cache/v1/x25519-key-agreement-2020-v1.json b/libs/w3cache/v1/x25519-key-agreement-2020-v1.json new file mode 100644 index 0000000..a12630a --- /dev/null +++ b/libs/w3cache/v1/x25519-key-agreement-2020-v1.json @@ -0,0 +1,30 @@ +{ + "@context": { + "id": "@id", + "type": "@type", + "@protected": true, + "X25519KeyAgreementKey2020": { + "@id": "https://w3id.org/security#X25519KeyAgreementKey2020", + "@context": { + "@protected": true, + "id": "@id", + "type": "@type", + "controller": { + "@id": "https://w3id.org/security#controller", + "@type": "@id" + }, + "revoked": { + "@id": "https://w3id.org/security#revoked", + "@type": "http://www.w3.org/2001/XMLSchema#dateTime" + }, + "publicKeyMultibase": { + "@id": "https://w3id.org/security#publicKeyMultibase", + "@type": "https://w3id.org/security#multibase" + }, + "blockchainAccountId": "https://w3id.org/security#blockchainAccountId" + + } + } + } + } + \ No newline at end of file diff --git a/src/constants.ts b/src/constants.ts index 7a2e7d5..9e1f9a0 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -43,6 +43,7 @@ export const DID_Ed25519VerificationKey2020 = { METHOD: 'hid', NAMESPACE: 'testnet', // this is not used DID_BASE_CONTEXT: 'https://www.w3.org/ns/did/v1', + DID_KEYAGREEMENT_CONTEXT:"https://digitalbazaar.github.io/x25519-key-agreement-2020-context/contexts/x25519-key-agreement-2020-v1.jsonld", VERIFICATION_METHOD_TYPE: 'Ed25519VerificationKey2020', BLOCKCHAINACCOUNTID_CONTEXT: 'https://w3c.github.io/vc-data-integrity/vocab/security/vocabulary.jsonld', @@ -55,8 +56,8 @@ export const DID_EcdsaSecp256k1RecoveryMethod2020 = { METHOD: 'hid', NAMESPACE: 'testnet', // this is not used DID_BASE_CONTEXT: 'https://www.w3.org/ns/did/v1', + DID_KEYAGREEMENT_CONTEXT:"https://github.com/hypersign-protocol/hid-ssi-js-sdk/blob/develop/libs/w3cache/v1/X25519KeyAgreementKeyEIP5630.json", BLOCKCHAINACCOUNTID_CONTEXT: 'https://w3c.github.io/vc-data-integrity/vocab/security/vocabulary.jsonld', - VERIFICATION_METHOD_TYPE: 'EcdsaSecp256k1RecoveryMethod2020', }; diff --git a/src/did/IDID.ts b/src/did/IDID.ts index 593facd..8869e72 100644 --- a/src/did/IDID.ts +++ b/src/did/IDID.ts @@ -24,13 +24,14 @@ export enum IKeyType { Ed25519VerificationKey2020 = 'Ed25519VerificationKey2020', EcdsaSecp256k1VerificationKey2019 = 'EcdsaSecp256k1VerificationKey2019', EcdsaSecp256k1RecoveryMethod2020 = 'EcdsaSecp256k1RecoveryMethod2020', + X25519KeyAgreementKey2020 = 'X25519KeyAgreementKey2020', + X25519KeyAgreementKeyEIP5630 = 'X25519KeyAgreementKeyEIP5630', } export enum IClientSpec { 'eth-personalSign' = 'eth-personalSign', 'cosmos-ADR036' = 'cosmos-ADR036', } - export interface IController { '@context': string; id: string; diff --git a/src/did/did.ts b/src/did/did.ts index 454f3f4..c850bad 100644 --- a/src/did/did.ts +++ b/src/did/did.ts @@ -30,7 +30,6 @@ import { import { ClientSpec } from '../../libs/generated/ssi/clientSpec'; import { OfflineSigner } from '@cosmjs/proto-signing'; import customLoader from '../../libs/w3cache/v1'; - class DIDDocument implements Did { context: string[]; id: string; @@ -208,7 +207,6 @@ export default class HypersignDID implements IDID { IVerificationRelationships.authentication, IVerificationRelationships.capabilityDelegation, IVerificationRelationships.capabilityInvocation, - IVerificationRelationships.keyAgreement, ]; if (verificationRelationships && verificationRelationships.length > 0) { const set1 = new Set(vR); @@ -289,6 +287,9 @@ export default class HypersignDID implements IDID { }): Promise { let verificationRelationships: IVerificationRelationships[] = []; if (params.verificationRelationships && params.verificationRelationships.length > 0) { + if (params.verificationRelationships.includes(IVerificationRelationships.keyAgreement)) { + throw new Error('HID-SSI-SDK:: Error: keyAgreement is not allowed in verificationRelationships'); + } verificationRelationships = this._filterVerificationRelationships(params.verificationRelationships); } else { verificationRelationships = this._filterVerificationRelationships([]); @@ -696,6 +697,9 @@ export default class HypersignDID implements IDID { let didDoc; let verificationRelationships: IVerificationRelationships[] = []; if (params.verificationRelationships && params.verificationRelationships.length > 0) { + if (params.verificationRelationships.includes(IVerificationRelationships.keyAgreement)) { + throw new Error('HID-SSI-SDK:: Error: keyAgreement is not allowed in verificationRelationships'); + } verificationRelationships = this._filterVerificationRelationships(params.verificationRelationships); } else { verificationRelationships = this._filterVerificationRelationships([]); @@ -1051,4 +1055,117 @@ export default class HypersignDID implements IDID { break; } } + + public async addVerificationMethod(params: { + did?: string; + didDocument?: Did; + type: IKeyType; + id?: string; // verificationMethodId + controller?: string; + publicKeyMultibase?: string; + blockchainAccountId?: string; + }): Promise { + let resolvedDidDoc; + + if (!params.did && (!params.didDocument || Object.keys(params.didDocument).length === 0)) { + throw new Error('HID-SSI_SDK:: Error: params.did or params.didDocument is required to addVerificationMethod'); + } + if (!params.type) { + throw new Error('HID-SSI-SDK:: Error: params.type is required to addVerificationMethod'); + } + const { type } = params; + if (!(type in IKeyType)) { + throw new Error('HID-SSI-SDK:: Error: params.type is invalid'); + } + try { + if (params.did) { + if (!this.didrpc) { + throw new Error( + 'HID-SSI-SDK:: Error: HID-SSI-SDK:: Error: HypersignDID class is not instantiated with Offlinesigner or have not been initilized' + ); + } + resolvedDidDoc = await this.didrpc.resolveDID(params.did); + if (!resolvedDidDoc.didDocument) { + if (!params.didDocument) { + throw new Error('HID-SSI_SDK:: Error: can not able to resolve did please send didDocument'); + } + } + } else if (params.didDocument) { + resolvedDidDoc = {}; + resolvedDidDoc.didDocument = params.didDocument; + } else { + throw new Error('HID-SSI-SDK:: Error: params.did or params.didDocument is required to addVerificationMethod'); + } + } catch (e) { + throw new Error(`HID-SSI-SDK:: Error: could not resolve did ${params.did}`); + } + if ( + type === IKeyType.EcdsaSecp256k1RecoveryMethod2020 && + (!params.blockchainAccountId || params.blockchainAccountId.trim() === '') + ) { + throw new Error(`HID-SSI-SDK:: Error: params.blockchainAccountId is required for keyType ${params.type}`); + } + if (type === IKeyType.EcdsaSecp256k1RecoveryMethod2020 && (!params.id || params.id.trim() === '')) { + throw new Error(`HID-SSI-SDK:: Error: params.id is required for keyType ${params.type}`); + } + if ( + type === IKeyType.EcdsaSecp256k1VerificationKey2019 && + (!params.blockchainAccountId || + params.blockchainAccountId.trim() === '' || + !params.publicKeyMultibase || + params.publicKeyMultibase.trim() === '') + ) { + throw new Error( + `HID-SSI-SDK:: Error: params.blockchainAccountId and params.publicKeyMultibase is required for keyType ${params.type}` + ); + } + + if ( + (type === IKeyType.Ed25519VerificationKey2020 || + type === IKeyType.X25519KeyAgreementKey2020 || + type === IKeyType.X25519KeyAgreementKeyEIP5630) && + !params.publicKeyMultibase + ) { + throw new Error('HID-SSI-SDK:: Error: params.publicKeyMultibase is required to addVerificationMethod'); + } + const verificationMethod = {} as VerificationMethod; + const { didDocument } = resolvedDidDoc; + if (params.id) { + const checkIfVmIdExists = didDocument.verificationMethod.some((vm) => vm.id === params.id); + if (checkIfVmIdExists) { + throw new Error(`HID-SSI-SDK:: Error: verificationMethod ${params.id} already exists`); + } + } + + const VMLength = didDocument.verificationMethod.length; + verificationMethod['id'] = params?.id ?? `${didDocument.id}#key-${VMLength + 1}`; + //verificationMethod['id'] = params?.id ?? `${didDocument.id}#${params.publicKeyMultibase}`; + verificationMethod['type'] = type; + verificationMethod['controller'] = didDocument.id; + if (type !== IKeyType.EcdsaSecp256k1RecoveryMethod2020) { + verificationMethod['publicKeyMultibase'] = params?.publicKeyMultibase ?? ''; + } + verificationMethod['blockchainAccountId'] = params?.blockchainAccountId ?? ''; + didDocument.verificationMethod.push(verificationMethod); + if ( + verificationMethod['type'] === IKeyType.X25519KeyAgreementKey2020 || + verificationMethod['type'] === IKeyType.X25519KeyAgreementKeyEIP5630 + ) { + didDocument.keyAgreement.push(verificationMethod['id']); + } else { + didDocument.authentication.push(verificationMethod['id']); + didDocument.assertionMethod.push(verificationMethod['id']); + didDocument.capabilityDelegation.push(verificationMethod['id']); + didDocument.capabilityInvocation.push(verificationMethod['id']); + } + if (verificationMethod['type'] === IKeyType.X25519KeyAgreementKey2020) { + didDocument['@context'].push(constant['DID_' + IKeyType.Ed25519VerificationKey2020].DID_KEYAGREEMENT_CONTEXT); + } + if (verificationMethod['type'] === IKeyType.X25519KeyAgreementKeyEIP5630) { + didDocument['@context'].push( + constant['DID_' + IKeyType.EcdsaSecp256k1RecoveryMethod2020].DID_KEYAGREEMENT_CONTEXT + ); + } + return didDocument; + } } diff --git a/src/tests/did.spec.ts b/src/tests/did.spec.ts index 7342943..02e7d5d 100644 --- a/src/tests/did.spec.ts +++ b/src/tests/did.spec.ts @@ -1,6 +1,6 @@ import { expect, should } from 'chai'; import { HypersignDID, HypersignSSISdk } from '../index'; -import { IPublicKey, IController, IDID } from '../did/IDID'; +import { IPublicKey, IController, IDID, IKeyType } from '../did/IDID'; import { createWallet, mnemonic, hidNodeEp } from './config'; let privateKeyMultibase; @@ -16,6 +16,8 @@ let signedDocument; const challenge = '1231231231'; const domain = 'www.adbv.com'; let hypersignSSISDK; +let pubKey; +let didDocToReg; //add mnemonic of wallet that have balance @@ -66,7 +68,6 @@ describe('DID Test scenarios', () => { it('should be able to generate didDocument', async function () { didDocument = await hypersignDID.generate({ publicKeyMultibase }); - //console.log(didDocument) didDocId = didDocument['id']; verificationMethodId = didDocument['verificationMethod'][0].id; expect(didDocument).to.be.a('object'); @@ -74,7 +75,6 @@ describe('DID Test scenarios', () => { should().exist(didDocument['id']); should().exist(didDocument['controller']); should().exist(didDocument['alsoKnownAs']); - should().exist(didDocument['verificationMethod']); expect( didDocument['verificationMethod'] && @@ -128,7 +128,33 @@ describe('DID Test scenarios', () => { expect(didDocument['service']).to.be.a('array').of.length(0); expect(didDocument['capabilityDelegation']).to.be.a('array').of.length(0); }); - + it('should be able to generate didDocument with different kp', async function () { + const kp = await hypersignDID.generateKeys(); + const privateKeyMultibase = kp.privateKeyMultibase; + pubKey = kp.publicKeyMultibase; + didDocToReg = await hypersignDID.generate({ publicKeyMultibase: pubKey }); + expect(didDocument).to.be.a('object'); + should().exist(didDocument['@context']); + should().exist(didDocument['id']); + should().exist(didDocument['controller']); + should().exist(didDocument['alsoKnownAs']); + should().exist(didDocument['verificationMethod']); + expect( + didDocument['verificationMethod'] && + didDocument['authentication'] && + didDocument['assertionMethod'] && + didDocument['keyAgreement'] && + didDocument['capabilityInvocation'] && + didDocument['capabilityDelegation'] && + didDocument['service'] + ).to.be.a('array'); + should().exist(didDocument['authentication']); + should().exist(didDocument['assertionMethod']); + should().exist(didDocument['keyAgreement']); + should().exist(didDocument['capabilityInvocation']); + should().exist(didDocument['capabilityDelegation']); + should().exist(didDocument['service']); + }); it('should be able to generate didDocument with custom id', async function () { const methodSpecificId = 'e157620d69d003e12d935c37b8c21baa78d24898398829b39d943d253c006332'; const didDocument = await hypersignDID.generate({ publicKeyMultibase, methodSpecificId }); @@ -199,7 +225,185 @@ describe('DID Test scenarios', () => { should().exist(didDocument['service']); }); }); + describe('#addVerificationMethod() to add verificationMethod in didDocument', function () { + it('should not be able to add verificationMethod as neither did nor didDoc is passed', async () => { + const params = { + didDocument: {}, + type: 'X25519KeyAgreementKey2020', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + expect(function () { + throw err; + }).to.throw( + Error, + 'HID-SSI_SDK:: Error: params.did or params.didDocument is required to addVerificationMethod' + ); + }); + }); + it('should not be able to add verificationMethod as type is not passed', async () => { + const params = { + didDocument, + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + expect(function () { + throw err; + }).to.throw(Error, 'HID-SSI-SDK:: Error: params.type is required to addVerificationMethod'); + }); + }); + it('should not be able to add verificationMethod as type passed is invalid', async () => { + const params = { + didDocument, + type: 'dsyifx', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + expect(function () { + throw err; + }).to.throw(Error, 'HID-SSI-SDK:: Error: params.type is invalid'); + }); + }); + + it('should not be able to add verificationMethod as params.did is passed but yet not registerd', async () => { + const params = { + did: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY', + type: IKeyType.Ed25519VerificationKey2020, + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + const hypersignDid = new HypersignDID({ namespace: 'testnet' }); + return hypersignDid.addVerificationMethod(params).catch(function (err) { + expect(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: could not resolve did ${params.did}`); + }); + }); + it('should not be able to add verificationMethod in didDocument as type is EcdsaSecp256k1RecoveryMethod2020 but blockchainAccountId is not passed', async () => { + const params = { + didDocument, + type: 'EcdsaSecp256k1RecoveryMethod2020', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + expect(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: params.blockchainAccountId is required for keyType ${params.type}`); + }); + }); + + it('should not be able to add verificationMethod in didDocument as type is EcdsaSecp256k1RecoveryMethod2020 but params.id is not passed', async () => { + const params = { + didDocument, + type: 'EcdsaSecp256k1RecoveryMethod2020', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + blockchainAccountId: 'eip155:1:23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + expect(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: params.id is required for keyType ${params.type}`); + }); + }); + it('should not be able to add verificationMethod in didDocument as type is EcdsaSecp256k1VerificationKey2019 but neither params.blockchainAccountId nor params.publicKeyMultibase is passed', async () => { + const params = { + didDocument, + type: 'EcdsaSecp256k1VerificationKey2019', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + expect(function () { + throw err; + }).to.throw( + Error, + `HID-SSI-SDK:: Error: params.blockchainAccountId and params.publicKeyMultibase is required for keyType ${params.type}` + ); + }); + }); + + it('should not be able to add verificationMethod in didDocument as type is EcdsaSecp256k1VerificationKey2019 params.publicKeyMultibase is not passed', async () => { + const params = { + didDocument, + type: 'EcdsaSecp256k1VerificationKey2019', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + blockchainAccountId: 'eip155:1:23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + expect(function () { + throw err; + }).to.throw( + Error, + `HID-SSI-SDK:: Error: params.blockchainAccountId and params.publicKeyMultibase is required for keyType ${params.type}` + ); + }); + }); + + it('should not be able to add verificationMethod in didDocument as type is EcdsaSecp256k1VerificationKey2019 params.blockchainAccountId is not passed', async () => { + const params = { + didDocument, + type: 'EcdsaSecp256k1VerificationKey2019', + id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + blockchainAccountId: 'eip155:1:23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + expect(function () { + throw err; + }).to.throw( + Error, + `HID-SSI-SDK:: Error: params.blockchainAccountId and params.publicKeyMultibase is required for keyType ${params.type}` + ); + }); + }); + + it('Should not be able to add verification method to didDocument as it is already exists', async () => { + const params = { + didDocument: didDocument, + type: 'X25519KeyAgreementKey2020', + id: `${didDocument.verificationMethod[0].id}`, + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + return hypersignDID.addVerificationMethod(params).catch(function (err) { + expect(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: verificationMethod ${params.id} already exists`); + }); + }); + + it('should be able to add verification method in didDocument', async () => { + const params = { + didDocument: didDocument, + type: 'X25519KeyAgreementKey2020', + // id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', + publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + }; + const didDoc = JSON.parse(JSON.stringify(didDocument)); + + const updatedDidDoc = await hypersignDID.addVerificationMethod(params); + expect(updatedDidDoc).to.be.a('object'); + should().exist(updatedDidDoc['@context']); + should().exist(updatedDidDoc['id']); + should().exist(updatedDidDoc['controller']); + should().exist(updatedDidDoc['alsoKnownAs']); + should().exist(updatedDidDoc['verificationMethod']); + expect( + updatedDidDoc['verificationMethod'] && + updatedDidDoc['authentication'] && + updatedDidDoc['assertionMethod'] && + updatedDidDoc['keyAgreement'] && + updatedDidDoc['capabilityInvocation'] && + updatedDidDoc['capabilityDelegation'] && + updatedDidDoc['service'] + ).to.be.a('array'); + should().exist(updatedDidDoc['authentication']); + should().exist(updatedDidDoc['assertionMethod']); + expect(updatedDidDoc.verificationMethod.length).to.be.greaterThan(didDoc.verificationMethod.length); + }); + }); describe('#register() this is to register did on the blockchain', function () { it('should not able to register did document and throw error as didDocument is not passed or it is empty', function () { return hypersignDID @@ -230,7 +434,6 @@ describe('DID Test scenarios', () => { }); it('should be able to register didDocument in the blockchain', async function () { const result = await hypersignDID.register({ didDocument, privateKeyMultibase, verificationMethodId }); - //console.log(result) transactionHash = result.transactionHash; should().exist(result.code); should().exist(result.height); @@ -254,7 +457,6 @@ describe('DID Test scenarios', () => { did: didDocId, }; const result = await hypersignDID.resolve(params); - //console.log(result); expect(result).to.be.a('object'); expect(result.didDocument.id).to.be.equal(didDocId); expect(result.didDocumentMetadata).to.be.a('object'); @@ -304,15 +506,12 @@ describe('DID Test scenarios', () => { }); it('should be able to update did document', async function () { didDocument['alsoKnownAs'].push('Some DATA'); - const result = await hypersignDID.update({ didDocument, privateKeyMultibase, verificationMethodId, versionId, }); - //console.log(result); - should().exist(result.code); should().exist(result.height); should().exist(result.rawLog); @@ -410,8 +609,6 @@ describe('DID Test scenarios', () => { verificationMethodId, versionId, }); - //console.log(JSON.stringify(result)); - should().exist(result.code); should().exist(result.height); should().exist(result.rawLog); @@ -535,7 +732,6 @@ describe('DID Test scenarios', () => { controller, }; signedDocument = await hypersignDID.sign(params); - //console.log(JSON.stringify(signedDocument)) expect(signedDocument).to.be.a('object'); should().exist(signedDocument['@context']); should().exist(signedDocument['id']); @@ -573,16 +769,12 @@ describe('DID Test scenarios', () => { }); it('should return verification result', async function () { - console.log(JSON.stringify(signedDocument, null, 2)); - const result = await hypersignDID.verify({ didDocument: signedDocument, verificationMethodId, challenge, domain, }); - console.log(result); - expect(result).to.be.a('object'); should().exist(result); should().exist(result.verified);