Skip to content

Commit a5244f8

Browse files
authored
Merge branch 'develop' into issues#74
2 parents 1c3bec9 + 2bf71c7 commit a5244f8

30 files changed

+905
-179
lines changed

build/src/constants.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.HID_MIN_FEE = exports.HID_MIN_GAS = exports.HID_DNOMINATION = exports.HID_DECIMAL = exports.GAS_PRICE = exports.KEY_HEADERS = exports.SCHEMA = exports.VP = exports.VC = exports.DID = exports.CredentialStatusEnums = exports.HIDRpcEnums = exports.HYPERSIGN_NETWORK_BANK_BALANCE_PATH = exports.HYPERSIGN_NETWORK_CREDENTIALSTATUS_PATH = exports.HYPERSIGN_NETWORK_SCHEMA_PATH = exports.HYPERSIGN_NETWORK_DID_PATH = exports.HID_COSMOS_MODULE = exports.HYPERSIGN_MAINNET_REST = exports.HYPERSIGN_MAINNET_RPC = exports.HYPERSIGN_TESTNET_REST = exports.HYPERSIGN_TESTNET_RPC = exports.compactProof = void 0;
3+
exports.HID_MIN_FEE = exports.HID_MIN_GAS = exports.HID_DNOMINATION = exports.HID_DECIMAL = exports.GAS_PRICE = exports.KEY_HEADERS = exports.SCHEMA = exports.VP = exports.VC = exports.DID = exports.CredentialStatusReasonEnums = exports.CredentialStatusEnums = exports.HIDRpcEnums = exports.HYPERSIGN_NETWORK_BANK_BALANCE_PATH = exports.HYPERSIGN_NETWORK_CREDENTIALSTATUS_PATH = exports.HYPERSIGN_NETWORK_SCHEMA_PATH = exports.HYPERSIGN_NETWORK_DID_PATH = exports.HID_COSMOS_MODULE = exports.HYPERSIGN_MAINNET_REST = exports.HYPERSIGN_MAINNET_RPC = exports.HYPERSIGN_TESTNET_REST = exports.HYPERSIGN_TESTNET_RPC = exports.compactProof = void 0;
44
exports.compactProof = false;
55
exports.HYPERSIGN_TESTNET_RPC = "http://localhost:26657";
66
exports.HYPERSIGN_TESTNET_REST = "http://localhost:1317";
@@ -23,7 +23,15 @@ Object.freeze(HIDRpcEnums);
2323
var CredentialStatusEnums;
2424
(function (CredentialStatusEnums) {
2525
CredentialStatusEnums["LIVE"] = "Live";
26+
CredentialStatusEnums["REVOKED"] = "Revoked";
27+
CredentialStatusEnums["SUSPENDED"] = "Suspended";
2628
})(CredentialStatusEnums = exports.CredentialStatusEnums || (exports.CredentialStatusEnums = {}));
29+
var CredentialStatusReasonEnums;
30+
(function (CredentialStatusReasonEnums) {
31+
CredentialStatusReasonEnums["LIVE"] = "Credential is live";
32+
CredentialStatusReasonEnums["REVOKED"] = "Credential is revoked";
33+
CredentialStatusReasonEnums["SUSPENDED"] = "Credential is suspended";
34+
})(CredentialStatusReasonEnums = exports.CredentialStatusReasonEnums || (exports.CredentialStatusReasonEnums = {}));
2735
exports.DID = {
2836
CONTROLLER_CONTEXT: "https://w3id.org/security/v2",
2937
SCHEME: "did",
@@ -44,8 +52,9 @@ exports.VC = {
4452
CREDENTAIL_SECURITY_CONTEXT_V2: "https://w3id.org/security/v2",
4553
CREDENTAIL_SECURITY_SUITE: "https://w3id.org/security/suites/ed25519-2020/v1",
4654
PROOF_PURPOSE: "assertion",
47-
VERIFICATION_METHOD_TYPE: "Ed25519VerificationKey2020",
48-
CRED_STATUS_TYPES: CredentialStatusEnums
55+
VERIFICATION_METHOD_TYPE: "Ed25519Signature2020",
56+
CRED_STATUS_TYPES: CredentialStatusEnums,
57+
CRED_STATUS_REASON_TYPES: CredentialStatusReasonEnums
4958
};
5059
Object.freeze(exports.VC);
5160
exports.VP = {

build/src/credential/credRPC.js

+39
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,45 @@ var CredentialRPC = /** @class */ (function () {
9898
});
9999
});
100100
};
101+
CredentialRPC.prototype.generateCredentialStatusTxnMessage = function (credentialStatus, proof) {
102+
return __awaiter(this, void 0, void 0, function () {
103+
var typeUrl, txMessage;
104+
return __generator(this, function (_a) {
105+
if (!credentialStatus) {
106+
throw new Error('CredentialStatus must be passed as a param while registerting credential status');
107+
}
108+
if (!proof) {
109+
throw new Error('Proof must be passed as a param while registering crdential status');
110+
}
111+
typeUrl = "".concat(constants_1.HID_COSMOS_MODULE, ".").concat(constants_1.HIDRpcEnums.MsgRegisterCredentialStatus);
112+
txMessage = {
113+
typeUrl: typeUrl,
114+
value: generatedProto[constants_1.HIDRpcEnums.MsgRegisterCredentialStatus].fromPartial({
115+
credentialStatus: credentialStatus,
116+
proof: proof,
117+
creator: client_1.HIDClient.getHidWalletAddress(),
118+
}),
119+
};
120+
return [2 /*return*/, txMessage];
121+
});
122+
});
123+
};
124+
CredentialRPC.prototype.registerCredentialStatusBulk = function (txMessages) {
125+
return __awaiter(this, void 0, void 0, function () {
126+
var fee, hidClient, txResult;
127+
return __generator(this, function (_a) {
128+
switch (_a.label) {
129+
case 0:
130+
fee = 'auto';
131+
hidClient = client_1.HIDClient.getHidClient();
132+
return [4 /*yield*/, hidClient.signAndBroadcast(client_1.HIDClient.getHidWalletAddress(), txMessages, fee)];
133+
case 1:
134+
txResult = _a.sent();
135+
return [2 /*return*/, txResult];
136+
}
137+
});
138+
});
139+
};
101140
CredentialRPC.prototype.resolveCredentialStatus = function (credentialId) {
102141
return __awaiter(this, void 0, void 0, function () {
103142
var get_didUrl, response, credStatus;

build/src/credential/vc.js

+154-9
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ var HypersignVerifiableCredential = /** @class */ (function () {
159159
return new Date(date).toISOString().slice(0, -5) + 'Z';
160160
}
161161
else {
162-
return new Date().toISOString().slice(0, -5) + 'Z';
162+
return new Date(new Date().getTime() - 100000).toISOString().slice(0, -5) + 'Z';
163163
}
164164
};
165165
HypersignVerifiableCredential.prototype.sha256Hash = function (message) {
@@ -349,7 +349,7 @@ var HypersignVerifiableCredential = /** @class */ (function () {
349349
};
350350
HypersignVerifiableCredential.prototype.issueCredential = function (params) {
351351
return __awaiter(this, void 0, void 0, function () {
352-
var signerDidDoc, publicKeyId, publicKeyVerMethod, convertedKeyPair, keyPair, suite, credentialHash, credentialStatus, proofValue, issuerDID, issuerDidDoc, issuerPublicKeyId, issuerPublicKeyVerMethod, proof, resp, signedVC;
352+
var signerDidDoc, publicKeyId, publicKeyVerMethod, convertedKeyPair, keyPair, suite, credentialHash, credentialStatus, proofValue, issuerDID, issuerDidDoc, issuerPublicKeyId, issuerPublicKeyVerMethod, proof, signedVC, resp;
353353
return __generator(this, function (_a) {
354354
switch (_a.label) {
355355
case 0:
@@ -365,6 +365,9 @@ var HypersignVerifiableCredential = /** @class */ (function () {
365365
if (!params.issuerDid) {
366366
throw new Error('HID-SSI-SDK:: Error: params.issuerDid is required to issue credential');
367367
}
368+
if (params.registerCredential == undefined) {
369+
params.registerCredential = true;
370+
}
368371
return [4 /*yield*/, this.hsDid.resolve({ did: params.issuerDid })];
369372
case 1:
370373
signerDidDoc = (_a.sent()).didDocument;
@@ -415,20 +418,162 @@ var HypersignVerifiableCredential = /** @class */ (function () {
415418
proofValue: proofValue,
416419
proofPurpose: constants_1.VC.PROOF_PURPOSE,
417420
};
418-
return [4 /*yield*/, this.credStatusRPC.registerCredentialStatus(credentialStatus, proof)];
419-
case 5:
420-
resp = _a.sent();
421-
if (!resp || resp.code != 0) {
422-
throw new Error('HID-SSI-SDK:: Error while issuing the credential error = ' + resp.rawLog);
423-
}
424421
return [4 /*yield*/, vc_js_1.default.issue({
425422
credential: params.credential,
426423
suite: suite,
427424
documentLoader: jsonld_1.documentLoader,
428425
})];
429-
case 6:
426+
case 5:
430427
signedVC = _a.sent();
428+
if (!params.registerCredential) return [3 /*break*/, 7];
429+
return [4 /*yield*/, this.credStatusRPC.registerCredentialStatus(credentialStatus, proof)];
430+
case 6:
431+
resp = _a.sent();
432+
if (!resp || resp.code != 0) {
433+
throw new Error('HID-SSI-SDK:: Error while issuing the credential error = ' + resp.rawLog);
434+
}
431435
return [2 /*return*/, signedVC];
436+
case 7: return [2 /*return*/, { signedVC: signedVC, credentialStatus: credentialStatus, proof: proof }];
437+
}
438+
});
439+
});
440+
};
441+
HypersignVerifiableCredential.prototype.registerCredentialStatus = function (credentialStatus, proof) {
442+
return __awaiter(this, void 0, void 0, function () {
443+
var resp;
444+
return __generator(this, function (_a) {
445+
switch (_a.label) {
446+
case 0:
447+
if (!credentialStatus || !proof)
448+
throw new Error('HID-SSI-SDK:: Error: credentialStatus and proof are required to register credential status');
449+
return [4 /*yield*/, this.credStatusRPC.registerCredentialStatus(credentialStatus, proof)];
450+
case 1:
451+
resp = _a.sent();
452+
if (!resp || resp.code != 0) {
453+
throw new Error('HID-SSI-SDK:: Error while issuing the credential error = ' + resp.rawLog);
454+
}
455+
return [2 /*return*/, resp];
456+
}
457+
});
458+
});
459+
};
460+
HypersignVerifiableCredential.prototype.updateCredentialStatus = function (params) {
461+
return __awaiter(this, void 0, void 0, function () {
462+
var signerDidDoc, publicKeyId, publicKeyVerMethod, convertedKeyPair, keyPair, suite, claim, credentialStatus, proofValue, issuerDID, issuerDidDoc, issuerPublicKeyId, issuerPublicKeyVerMethod, proof, resp;
463+
return __generator(this, function (_a) {
464+
switch (_a.label) {
465+
case 0:
466+
if (!params.verificationMethodId) {
467+
throw new Error('HID-SSI-SDK:: Error: params.verificationMethodId is required revoke credential');
468+
}
469+
if (!params.credStatus) {
470+
throw new Error('HID-SSI-SDK:: Error: params.credential is required to revoke credential');
471+
}
472+
if (!params.privateKey) {
473+
throw new Error('HID-SSI-SDK:: Error: params.privateKey is required to revoke credential');
474+
}
475+
if (!params.issuerDid) {
476+
throw new Error('HID-SSI-SDK:: Error: params.issuerDid is required to revoke credential');
477+
}
478+
if (!params.status) {
479+
throw new Error('HID-SSI-SDK:: Error: params.status is required to revoke credential');
480+
}
481+
return [4 /*yield*/, this.hsDid.resolve({ did: params.issuerDid })];
482+
case 1:
483+
signerDidDoc = (_a.sent()).didDocument;
484+
if (!signerDidDoc)
485+
throw new Error('Could not resolve issuerDid = ' + params.issuerDid);
486+
publicKeyId = params.verificationMethodId;
487+
publicKeyVerMethod = signerDidDoc['verificationMethod'].find(function (x) { return x.id == publicKeyId; });
488+
convertedKeyPair = utils_1.default.convertedStableLibKeysIntoEd25519verificationkey2020({
489+
publicKey: publicKeyVerMethod.publicKeyMultibase,
490+
});
491+
publicKeyVerMethod['publicKeyMultibase'] = convertedKeyPair.publicKeyMultibase;
492+
return [4 /*yield*/, ed25519_verification_key_2020_1.Ed25519VerificationKey2020.from(__assign({ privateKeyMultibase: params.privateKey }, publicKeyVerMethod))];
493+
case 2:
494+
keyPair = _a.sent();
495+
suite = new ed25519_signature_2020_1.Ed25519Signature2020({
496+
verificationMethod: publicKeyId,
497+
key: keyPair,
498+
});
499+
/// Before we issue the credential the credential status has to be added
500+
/// for that we will call RegisterCredentialStatus RPC
501+
// Let us generate credentialHash first
502+
params.status = params.status.toUpperCase();
503+
claim = params.credStatus.claim;
504+
credentialStatus = {
505+
claim: {
506+
id: claim.id,
507+
currentStatus: constants_1.VC.CRED_STATUS_TYPES[params.status],
508+
statusReason: params.statusReason ? params.statusReason : constants_1.VC.CRED_STATUS_REASON_TYPES[params.status],
509+
},
510+
issuer: params.credStatus.issuer,
511+
issuanceDate: params.credStatus.issuanceDate,
512+
expirationDate: params.credStatus.expirationDate,
513+
credentialHash: params.credStatus.credentialHash,
514+
};
515+
return [4 /*yield*/, this.sign({
516+
message: JSON.stringify(credentialStatus),
517+
privateKeyMultibase: params.privateKey,
518+
})];
519+
case 3:
520+
proofValue = _a.sent();
521+
return [4 /*yield*/, this.hsDid.resolve({ did: params.credStatus.issuer })];
522+
case 4:
523+
issuerDID = (_a.sent()).didDocument;
524+
issuerDidDoc = issuerDID;
525+
issuerPublicKeyId = params.verificationMethodId;
526+
issuerPublicKeyVerMethod = issuerDidDoc.verificationMethod.find(function (x) { return x.id == issuerPublicKeyId; });
527+
proof = {
528+
type: constants_1.VC.VERIFICATION_METHOD_TYPE,
529+
created: params.credStatus.issuanceDate,
530+
updated: this.dateNow(),
531+
verificationMethod: issuerPublicKeyVerMethod.id,
532+
proofValue: proofValue,
533+
proofPurpose: constants_1.VC.PROOF_PURPOSE,
534+
};
535+
return [4 /*yield*/, this.credStatusRPC.registerCredentialStatus(credentialStatus, proof)];
536+
case 5:
537+
resp = _a.sent();
538+
if (!resp || resp.code != 0) {
539+
throw new Error('HID-SSI-SDK:: Error while revoking the credential error = ' + resp.rawLog);
540+
}
541+
return [2 /*return*/, resp];
542+
}
543+
});
544+
});
545+
};
546+
HypersignVerifiableCredential.prototype.generateRegisterCredentialStatusTxnMessage = function (credentialStatus, proof) {
547+
return __awaiter(this, void 0, void 0, function () {
548+
var txnMessage;
549+
return __generator(this, function (_a) {
550+
switch (_a.label) {
551+
case 0:
552+
if (!credentialStatus || !proof)
553+
throw new Error('HID-SSI-SDK:: Error: credentialStatus and proof are required to register credential status');
554+
return [4 /*yield*/, this.credStatusRPC.generateCredentialStatusTxnMessage(credentialStatus, proof)];
555+
case 1:
556+
txnMessage = _a.sent();
557+
return [2 /*return*/, txnMessage];
558+
}
559+
});
560+
});
561+
};
562+
HypersignVerifiableCredential.prototype.registerCredentialStatusTxnBulk = function (txnMessage) {
563+
return __awaiter(this, void 0, void 0, function () {
564+
var resp;
565+
return __generator(this, function (_a) {
566+
switch (_a.label) {
567+
case 0:
568+
if (!txnMessage)
569+
throw new Error('HID-SSI-SDK:: Error: txnMessage is required to register credential status');
570+
return [4 /*yield*/, this.credStatusRPC.registerCredentialStatusBulk(txnMessage)];
571+
case 1:
572+
resp = _a.sent();
573+
if (!resp || resp.code != 0) {
574+
throw new Error('HID-SSI-SDK:: Error while issuing the credential error = ' + resp.rawLog);
575+
}
576+
return [2 /*return*/, resp];
432577
}
433578
});
434579
});

build/src/did/did.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -211,23 +211,29 @@ var HypersignDID = /** @class */ (function () {
211211
});
212212
});
213213
};
214-
/**
215-
* @param params params: { did?: string }
216-
*
217-
* if did is provided then it will resolve the did doc from the blockchain
218-
*
219-
* @returns Promise : {context ,didDocument, VerificationResult , didDocumentMetadata}
220-
*/
221214
HypersignDID.prototype.resolve = function (params) {
222215
return __awaiter(this, void 0, void 0, function () {
223-
var result;
216+
var result, didDoc, verificationMethods;
224217
return __generator(this, function (_a) {
225218
switch (_a.label) {
226219
case 0:
227220
if (!params.did) return [3 /*break*/, 2];
228221
return [4 /*yield*/, this.didrpc.resolveDID(params.did)];
229222
case 1:
230223
result = _a.sent();
224+
if (params.ed25519verificationkey2020) {
225+
didDoc = result.didDocument;
226+
verificationMethods = didDoc.verificationMethod;
227+
verificationMethods.forEach(function (verificationMethod) {
228+
if (verificationMethod.type === 'Ed25519VerificationKey2020') {
229+
var ed25519PublicKey = utils_1.default.convertedStableLibKeysIntoEd25519verificationkey2020({
230+
publicKey: verificationMethod.publicKeyMultibase,
231+
});
232+
verificationMethod.publicKeyMultibase = ed25519PublicKey.publicKeyMultibase;
233+
}
234+
});
235+
didDoc.verificationMethod = verificationMethods;
236+
}
231237
return [2 /*return*/, {
232238
didDocument: utils_1.default.jsonToLdConvertor(result.didDocument),
233239
didDocumentMetadata: result.didDocumentMetadata,

0 commit comments

Comments
 (0)