From 23be7735fd3473c66314dd745535923dd344e9b8 Mon Sep 17 00:00:00 2001 From: varsha766 Date: Fri, 21 Jul 2023 09:14:25 +0530 Subject: [PATCH 1/7] added api call for generating access token and did --- build/src/ssiApi/apiAuth/IAuth.d.ts | 9 +++ build/src/ssiApi/apiAuth/IAuth.d.ts.map | 1 + build/src/ssiApi/apiAuth/IAuth.js | 2 + build/src/ssiApi/apiAuth/apiAuth.d.ts | 7 +++ build/src/ssiApi/apiAuth/apiAuth.d.ts.map | 1 + build/src/ssiApi/apiAuth/apiAuth.js | 45 +++++++++++++++ build/src/ssiApi/services/IDid.d.ts | 13 +++++ build/src/ssiApi/services/IDid.d.ts.map | 1 + build/src/ssiApi/services/IDid.js | 2 + .../src/ssiApi/services/did/did.service.d.ts | 9 +++ .../ssiApi/services/did/did.service.d.ts.map | 1 + build/src/ssiApi/services/did/did.service.js | 55 +++++++++++++++++++ src/ssiApi/apiAuth/IAuth.ts | 9 +++ src/ssiApi/apiAuth/apiAuth.ts | 29 ++++++++++ src/ssiApi/services/IDid.ts | 13 +++++ src/ssiApi/services/did/did.service.ts | 47 ++++++++++++++++ 16 files changed, 244 insertions(+) create mode 100644 build/src/ssiApi/apiAuth/IAuth.d.ts create mode 100644 build/src/ssiApi/apiAuth/IAuth.d.ts.map create mode 100644 build/src/ssiApi/apiAuth/IAuth.js create mode 100644 build/src/ssiApi/apiAuth/apiAuth.d.ts create mode 100644 build/src/ssiApi/apiAuth/apiAuth.d.ts.map create mode 100644 build/src/ssiApi/apiAuth/apiAuth.js create mode 100644 build/src/ssiApi/services/IDid.d.ts create mode 100644 build/src/ssiApi/services/IDid.d.ts.map create mode 100644 build/src/ssiApi/services/IDid.js create mode 100644 build/src/ssiApi/services/did/did.service.d.ts create mode 100644 build/src/ssiApi/services/did/did.service.d.ts.map create mode 100644 build/src/ssiApi/services/did/did.service.js create mode 100644 src/ssiApi/apiAuth/IAuth.ts create mode 100644 src/ssiApi/apiAuth/apiAuth.ts create mode 100644 src/ssiApi/services/IDid.ts create mode 100644 src/ssiApi/services/did/did.service.ts diff --git a/build/src/ssiApi/apiAuth/IAuth.d.ts b/build/src/ssiApi/apiAuth/IAuth.d.ts new file mode 100644 index 0000000..127231a --- /dev/null +++ b/build/src/ssiApi/apiAuth/IAuth.d.ts @@ -0,0 +1,9 @@ +export interface IAuth { + generateAccessToken(): Promise; +} +export interface IgenerateToken { + access_token: string; + expiresIn: number; + tokenType: string; +} +//# sourceMappingURL=IAuth.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/apiAuth/IAuth.d.ts.map b/build/src/ssiApi/apiAuth/IAuth.d.ts.map new file mode 100644 index 0000000..9335771 --- /dev/null +++ b/build/src/ssiApi/apiAuth/IAuth.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"IAuth.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/apiAuth/IAuth.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IAClB,mBAAmB,IAAG,OAAO,CAAC,cAAc,CAAC,CAAA;CAChD;AAED,MAAM,WAAW,cAAc;IAC3B,YAAY,EAAC,MAAM,CAAC;IACnB,SAAS,EAAC,MAAM,CAAC;IACjB,SAAS,EAAC,MAAM,CAAC;CACrB"} \ No newline at end of file diff --git a/build/src/ssiApi/apiAuth/IAuth.js b/build/src/ssiApi/apiAuth/IAuth.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/build/src/ssiApi/apiAuth/IAuth.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/src/ssiApi/apiAuth/apiAuth.d.ts b/build/src/ssiApi/apiAuth/apiAuth.d.ts new file mode 100644 index 0000000..ee35004 --- /dev/null +++ b/build/src/ssiApi/apiAuth/apiAuth.d.ts @@ -0,0 +1,7 @@ +import { IgenerateToken } from "./IAuth"; +export declare class ApiAuth { + private apiKey; + constructor(apiKey: any); + generateAccessToken(): Promise; +} +//# sourceMappingURL=apiAuth.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/apiAuth/apiAuth.d.ts.map b/build/src/ssiApi/apiAuth/apiAuth.d.ts.map new file mode 100644 index 0000000..4500010 --- /dev/null +++ b/build/src/ssiApi/apiAuth/apiAuth.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"apiAuth.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/apiAuth/apiAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,qBAAa,OAAO;IAChB,OAAO,CAAC,MAAM,CAAS;gBACX,MAAM,KAAA;IAMZ,mBAAmB,IAAI,OAAO,CAAC,cAAc,CAAC;CAkBvD"} \ No newline at end of file diff --git a/build/src/ssiApi/apiAuth/apiAuth.js b/build/src/ssiApi/apiAuth/apiAuth.js new file mode 100644 index 0000000..e1752c0 --- /dev/null +++ b/build/src/ssiApi/apiAuth/apiAuth.js @@ -0,0 +1,45 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ApiAuth = void 0; +const node_fetch_1 = __importDefault(require("node-fetch")); +class ApiAuth { + constructor(apiKey) { + if (!apiKey || apiKey.trim() === "") { + throw new Error("HID-SSI_SDK:: Error: Please Provide apiKey"); + } + this.apiKey = apiKey; + } + generateAccessToken() { + return __awaiter(this, void 0, void 0, function* () { + const studioApiUrl = "https://api.entity.hypersign.id/api/v1/app/oauth"; + const headers = { + "X-Api-Secret-Key": this.apiKey, + "Origin": "https://entity.hypersign.id" + }; + const requestOptions = { + method: "POST", + headers, + }; + const response = yield (0, node_fetch_1.default)(studioApiUrl, requestOptions); + if (!response.ok) { + // what error to send not getting error message from api + throw new Error('HID-SSI_SDK:: Error: Unauthorized'); + } + const authToken = yield response.json(); + return authToken; + }); + } +} +exports.ApiAuth = ApiAuth; diff --git a/build/src/ssiApi/services/IDid.d.ts b/build/src/ssiApi/services/IDid.d.ts new file mode 100644 index 0000000..f6409c4 --- /dev/null +++ b/build/src/ssiApi/services/IDid.d.ts @@ -0,0 +1,13 @@ +import { IKeyType, IVerificationRelationships } from "../../did/IDID"; +export interface IGenerateDid { + namespace: string; + methodSpecificId?: string; + options?: { + keyType: IKeyType; + chainId: string; + publicKey: string; + walletAddress: string; + verificationRelationships: IVerificationRelationships[]; + }; +} +//# sourceMappingURL=IDid.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/services/IDid.d.ts.map b/build/src/ssiApi/services/IDid.d.ts.map new file mode 100644 index 0000000..b32429b --- /dev/null +++ b/build/src/ssiApi/services/IDid.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"IDid.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/services/IDid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,WAAW,YAAY;IACzB,SAAS,EAAC,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAC,MAAM,CAAC;IACzB,OAAO,CAAC,EAAC;QACL,OAAO,EAAC,QAAQ,CAAC;QACjB,OAAO,EAAC,MAAM,CAAC;QACf,SAAS,EAAC,MAAM,CAAC;QACjB,aAAa,EAAC,MAAM,CAAC;QACrB,yBAAyB,EAAC,0BAA0B,EAAE,CAAA;KACzD,CAAA;CACJ"} \ No newline at end of file diff --git a/build/src/ssiApi/services/IDid.js b/build/src/ssiApi/services/IDid.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/build/src/ssiApi/services/IDid.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/src/ssiApi/services/did/did.service.d.ts b/build/src/ssiApi/services/did/did.service.d.ts new file mode 100644 index 0000000..8932939 --- /dev/null +++ b/build/src/ssiApi/services/did/did.service.d.ts @@ -0,0 +1,9 @@ +import { IGenerateDid } from "../IDid"; +export declare class DID { + private authService; + private accessToken; + constructor(apiKey: string); + private initAccessToken; + generateDid(params: IGenerateDid): Promise; +} +//# sourceMappingURL=did.service.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/services/did/did.service.d.ts.map b/build/src/ssiApi/services/did/did.service.d.ts.map new file mode 100644 index 0000000..54207fb --- /dev/null +++ b/build/src/ssiApi/services/did/did.service.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"did.service.d.ts","sourceRoot":"","sources":["../../../../../src/ssiApi/services/did/did.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAGtC,qBAAa,GAAG;IACd,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,WAAW,CAAA;gBACP,MAAM,EAAE,MAAM;YAKZ,eAAe;IAIhB,WAAW,CAAC,MAAM,EAAE,YAAY;CAqB9C"} \ No newline at end of file diff --git a/build/src/ssiApi/services/did/did.service.js b/build/src/ssiApi/services/did/did.service.js new file mode 100644 index 0000000..c659476 --- /dev/null +++ b/build/src/ssiApi/services/did/did.service.js @@ -0,0 +1,55 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DID = void 0; +const apiAuth_1 = require("../../apiAuth/apiAuth"); +const node_fetch_1 = __importDefault(require("node-fetch")); +class DID { + constructor(apiKey) { + this.authService = new apiAuth_1.ApiAuth(apiKey); + this.initAccessToken(); + } + initAccessToken() { + return __awaiter(this, void 0, void 0, function* () { + const accessToken = yield this.authService.generateAccessToken(); + this.accessToken = accessToken.access_token; + }); + } + generateDid(params) { + return __awaiter(this, void 0, void 0, function* () { + const apiUrl = "https://api.entity.hypersign.id/api/v1/did/create"; + const headers = { + "Content-Type": "application/json", + Authorization: `Bearer ${this.accessToken}`, + Origin: "https://entity.hypersign.id" + }; + const requestOptions = { + method: "POST", + headers, + body: JSON.stringify(Object.assign({}, params)) + }; + const response = yield (0, node_fetch_1.default)(apiUrl, requestOptions); + if (!response.ok) { + // need to figure out how to send correct error message as not getting exact message from studio + throw new Error('HID-SSI_SDK:: Error: Issue in generating did'); + } + const { metaData } = yield response.json(); + return metaData.didDocument; + }); + } +} +exports.DID = DID; +// const test = new DID("c4dae4b264f98798920ad22456c6f.acd24a3adeaed7fddf86044925d419afc252ada299b018e961ed3ac3ae2d1aaebd577eb0550c2c011fd9f51d33097d88a") +const test = new DID("586a74602fffda655f186ca9c162f.445dbab93f8b3b24501a9bdb1254de6a1528d4db306d87e2674f2277ddcc40a5b6686c4b2fe996ae11509d72eb4bb0d38"); +console.log(test, "test"); diff --git a/src/ssiApi/apiAuth/IAuth.ts b/src/ssiApi/apiAuth/IAuth.ts new file mode 100644 index 0000000..01f0feb --- /dev/null +++ b/src/ssiApi/apiAuth/IAuth.ts @@ -0,0 +1,9 @@ +export interface IAuth{ + generateAccessToken():Promise +} + +export interface IgenerateToken{ + access_token:string; + expiresIn:number; + tokenType:string; +} \ No newline at end of file diff --git a/src/ssiApi/apiAuth/apiAuth.ts b/src/ssiApi/apiAuth/apiAuth.ts new file mode 100644 index 0000000..38befa9 --- /dev/null +++ b/src/ssiApi/apiAuth/apiAuth.ts @@ -0,0 +1,29 @@ +import fetch from "node-fetch" +import { IgenerateToken } from "./IAuth"; +export class ApiAuth { + private apiKey: string; + constructor(apiKey) { + if (!apiKey || apiKey.trim() === "") { + throw new Error("HID-SSI_SDK:: Error: Please Provide apiKey") + } + this.apiKey = apiKey + } + async generateAccessToken(): Promise { + const studioApiUrl = "https://api.entity.hypersign.id/api/v1/app/oauth" + const headers = { + "X-Api-Secret-Key": this.apiKey, + "Origin": "https://entity.hypersign.id" + } + const requestOptions = { + method: "POST", + headers, + } + const response = await fetch(studioApiUrl, requestOptions) + if (!response.ok) { + // what error to send not getting error message from api + throw new Error('HID-SSI_SDK:: Error: Unauthorized') + } + const authToken = await response.json() + return authToken + } +} diff --git a/src/ssiApi/services/IDid.ts b/src/ssiApi/services/IDid.ts new file mode 100644 index 0000000..ff55748 --- /dev/null +++ b/src/ssiApi/services/IDid.ts @@ -0,0 +1,13 @@ +import { IKeyType, IVerificationRelationships } from "../../did/IDID"; + +export interface IGenerateDid{ + namespace:string; + methodSpecificId?:string; + options?:{ + keyType:IKeyType, + chainId:string, + publicKey:string, + walletAddress:string, + verificationRelationships:IVerificationRelationships[] + } +} \ No newline at end of file diff --git a/src/ssiApi/services/did/did.service.ts b/src/ssiApi/services/did/did.service.ts new file mode 100644 index 0000000..f679428 --- /dev/null +++ b/src/ssiApi/services/did/did.service.ts @@ -0,0 +1,47 @@ +import { IAuth } from "../../apiAuth/IAuth" +import { ApiAuth } from "../../apiAuth/apiAuth" +import { IGenerateDid } from "../IDid" +import fetch from "node-fetch" + +export class DID { + private authService: IAuth + private accessToken + constructor(apiKey: string) { + this.authService = new ApiAuth(apiKey); + this.initAccessToken() + } + + private async initAccessToken() { + const accessToken = await this.authService.generateAccessToken() + this.accessToken = accessToken.access_token + } + public async generateDid(params: IGenerateDid) { + const apiUrl = "https://api.entity.hypersign.id/api/v1/did/create" + const headers = { + "Content-Type": "application/json", + Authorization: `Bearer ${this.accessToken}`, + Origin: "https://entity.hypersign.id" + } + const requestOptions = { + method: "POST", + headers, + body: JSON.stringify({ ...params }) + } + const response = await fetch(apiUrl, requestOptions) + if (!response.ok) { + // need to figure out how to send correct error message as not getting exact message from studio + throw new Error('HID-SSI_SDK:: Error: Issue in generating did') + } + const { metaData } = await response.json() + return metaData.didDocument + } + +} + + + + +// const test = new DID("c4dae4b264f98798920ad22456c6f.acd24a3adeaed7fddf86044925d419afc252ada299b018e961ed3ac3ae2d1aaebd577eb0550c2c011fd9f51d33097d88a") +const test = new DID("586a74602fffda655f186ca9c162f.445dbab93f8b3b24501a9bdb1254de6a1528d4db306d87e2674f2277ddcc40a5b6686c4b2fe996ae11509d72eb4bb0d38") + +console.log(test, "test") \ No newline at end of file From 29a9b4db8d40e9400bfbed82029f11ffc8983434 Mon Sep 17 00:00:00 2001 From: varsha766 Date: Mon, 24 Jul 2023 10:04:39 +0530 Subject: [PATCH 2/7] added api for register and resolve did as well fixed the issue of not getting correct error response --- build/src/ssiApi/api-constant.d.ts | 11 ++ build/src/ssiApi/api-constant.d.ts.map | 1 + build/src/ssiApi/api-constant.js | 13 ++ build/src/ssiApi/apiAuth/apiAuth.d.ts.map | 2 +- build/src/ssiApi/apiAuth/apiAuth.js | 9 +- build/src/ssiApi/services/IDid.d.ts | 21 ++- build/src/ssiApi/services/IDid.d.ts.map | 2 +- .../src/ssiApi/services/did/did.service.d.ts | 11 +- .../ssiApi/services/did/did.service.d.ts.map | 2 +- build/src/ssiApi/services/did/did.service.js | 103 +++++++++++-- src/ssiApi/api-constant.ts | 10 ++ src/ssiApi/apiAuth/apiAuth.ts | 33 ++--- src/ssiApi/services/IDid.ts | 24 +++- src/ssiApi/services/did/did.service.ts | 136 ++++++++++++++---- 14 files changed, 314 insertions(+), 64 deletions(-) create mode 100644 build/src/ssiApi/api-constant.d.ts create mode 100644 build/src/ssiApi/api-constant.d.ts.map create mode 100644 build/src/ssiApi/api-constant.js create mode 100644 src/ssiApi/api-constant.ts diff --git a/build/src/ssiApi/api-constant.d.ts b/build/src/ssiApi/api-constant.d.ts new file mode 100644 index 0000000..0005b17 --- /dev/null +++ b/build/src/ssiApi/api-constant.d.ts @@ -0,0 +1,11 @@ +export declare const APIENDPOINT: { + STUDIO_API_BASE_URL: string; + AUTH: string; + DID: { + CREATE_DID_ENDPOINT: string; + REGISTER_DID_ENDPOINT: string; + UPDATE_DID_ENDPOINT: string; + RESOLVE_DID_ENDPOINT: string; + }; +}; +//# sourceMappingURL=api-constant.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/api-constant.d.ts.map b/build/src/ssiApi/api-constant.d.ts.map new file mode 100644 index 0000000..18677a6 --- /dev/null +++ b/build/src/ssiApi/api-constant.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"api-constant.d.ts","sourceRoot":"","sources":["../../../src/ssiApi/api-constant.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW;;;;;;;;;CASvB,CAAC"} \ No newline at end of file diff --git a/build/src/ssiApi/api-constant.js b/build/src/ssiApi/api-constant.js new file mode 100644 index 0000000..2a7d59d --- /dev/null +++ b/build/src/ssiApi/api-constant.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.APIENDPOINT = void 0; +exports.APIENDPOINT = { + STUDIO_API_BASE_URL: 'https://api.entity.hypersign.id/api/v1', + AUTH: '/app/oauth', + DID: { + CREATE_DID_ENDPOINT: '/did/create', + REGISTER_DID_ENDPOINT: '/did/register', + UPDATE_DID_ENDPOINT: '/did', + RESOLVE_DID_ENDPOINT: '/did/resolve', + }, +}; diff --git a/build/src/ssiApi/apiAuth/apiAuth.d.ts.map b/build/src/ssiApi/apiAuth/apiAuth.d.ts.map index 4500010..dfd5ffe 100644 --- a/build/src/ssiApi/apiAuth/apiAuth.d.ts.map +++ b/build/src/ssiApi/apiAuth/apiAuth.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"apiAuth.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/apiAuth/apiAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,qBAAa,OAAO;IAChB,OAAO,CAAC,MAAM,CAAS;gBACX,MAAM,KAAA;IAMZ,mBAAmB,IAAI,OAAO,CAAC,cAAc,CAAC;CAkBvD"} \ No newline at end of file +{"version":3,"file":"apiAuth.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/apiAuth/apiAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,qBAAa,OAAO;IAChB,OAAO,CAAC,MAAM,CAAS;gBACX,MAAM,KAAA;IAMZ,mBAAmB,IAAI,OAAO,CAAC,cAAc,CAAC;CAkBvD"} \ No newline at end of file diff --git a/build/src/ssiApi/apiAuth/apiAuth.js b/build/src/ssiApi/apiAuth/apiAuth.js index e1752c0..b8e8e06 100644 --- a/build/src/ssiApi/apiAuth/apiAuth.js +++ b/build/src/ssiApi/apiAuth/apiAuth.js @@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiAuth = void 0; const node_fetch_1 = __importDefault(require("node-fetch")); +const api_constant_1 = require("../api-constant"); class ApiAuth { constructor(apiKey) { if (!apiKey || apiKey.trim() === "") { @@ -23,21 +24,19 @@ class ApiAuth { } generateAccessToken() { return __awaiter(this, void 0, void 0, function* () { - const studioApiUrl = "https://api.entity.hypersign.id/api/v1/app/oauth"; + const studioApiUrl = `${api_constant_1.APIENDPOINT.STUDIO_API_BASE_URL}${api_constant_1.APIENDPOINT.AUTH}`; const headers = { "X-Api-Secret-Key": this.apiKey, - "Origin": "https://entity.hypersign.id" }; const requestOptions = { method: "POST", headers, }; const response = yield (0, node_fetch_1.default)(studioApiUrl, requestOptions); + const authToken = yield response.json(); if (!response.ok) { - // what error to send not getting error message from api - throw new Error('HID-SSI_SDK:: Error: Unauthorized'); + throw new Error(`HID-SSI-SDK:: Error: ${authToken.message}`); } - const authToken = yield response.json(); return authToken; }); } diff --git a/build/src/ssiApi/services/IDid.d.ts b/build/src/ssiApi/services/IDid.d.ts index f6409c4..2317f69 100644 --- a/build/src/ssiApi/services/IDid.d.ts +++ b/build/src/ssiApi/services/IDid.d.ts @@ -1,4 +1,5 @@ -import { IKeyType, IVerificationRelationships } from "../../did/IDID"; +import { Did } from "../../../libs/generated/ssi/did"; +import { IClientSpec, IKeyType, IVerificationRelationships } from "../../did/IDID"; export interface IGenerateDid { namespace: string; methodSpecificId?: string; @@ -10,4 +11,22 @@ export interface IGenerateDid { verificationRelationships: IVerificationRelationships[]; }; } +interface ClientSpec { + type: IClientSpec; + adr036SignerAddress?: string; +} +interface SignInfo { + verification_method_id: string; + signature: string; + clientSpec: ClientSpec; +} +export interface IRegister { + didDocument: Did; + verificationMethodId?: string; + signInfos?: Array; +} +export interface IUpdate extends IRegister { + deactivate: boolean; +} +export {}; //# sourceMappingURL=IDid.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/services/IDid.d.ts.map b/build/src/ssiApi/services/IDid.d.ts.map index b32429b..7ce23b1 100644 --- a/build/src/ssiApi/services/IDid.d.ts.map +++ b/build/src/ssiApi/services/IDid.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IDid.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/services/IDid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,WAAW,YAAY;IACzB,SAAS,EAAC,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAC,MAAM,CAAC;IACzB,OAAO,CAAC,EAAC;QACL,OAAO,EAAC,QAAQ,CAAC;QACjB,OAAO,EAAC,MAAM,CAAC;QACf,SAAS,EAAC,MAAM,CAAC;QACjB,aAAa,EAAC,MAAM,CAAC;QACrB,yBAAyB,EAAC,0BAA0B,EAAE,CAAA;KACzD,CAAA;CACJ"} \ No newline at end of file +{"version":3,"file":"IDid.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/services/IDid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAEnF,MAAM,WAAW,YAAY;IACzB,SAAS,EAAC,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAC,MAAM,CAAC;IACzB,OAAO,CAAC,EAAC;QACL,OAAO,EAAC,QAAQ,CAAC;QACjB,OAAO,EAAC,MAAM,CAAC;QACf,SAAS,EAAC,MAAM,CAAC;QACjB,aAAa,EAAC,MAAM,CAAC;QACrB,yBAAyB,EAAC,0BAA0B,EAAE,CAAA;KACzD,CAAA;CACJ;AAED,UAAU,UAAU;IAChB,IAAI,EAAC,WAAW,CAAC;IACjB,mBAAmB,CAAC,EAAC,MAAM,CAAC;CAC/B;AACD,UAAU,QAAQ;IACd,sBAAsB,EAAC,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAC,UAAU,CAAA;CACxB;AACD,MAAM,WAAW,SAAS;IACtB,WAAW,EAAC,GAAG,CAAC;IAChB,oBAAoB,CAAC,EAAC,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;CAE7B;AAGD,MAAM,WAAW,OAAQ,SAAQ,SAAS;IACtC,UAAU,EAAC,OAAO,CAAA;CACrB"} \ No newline at end of file diff --git a/build/src/ssiApi/services/did/did.service.d.ts b/build/src/ssiApi/services/did/did.service.d.ts index 8932939..2f436ec 100644 --- a/build/src/ssiApi/services/did/did.service.d.ts +++ b/build/src/ssiApi/services/did/did.service.d.ts @@ -1,9 +1,18 @@ -import { IGenerateDid } from "../IDid"; +import { Did } from '../../../../libs/generated/ssi/did'; +import { IDIDResolve } from '../../../did/IDID'; +import { IGenerateDid, IRegister } from '../IDid'; export declare class DID { private authService; private accessToken; constructor(apiKey: string); private initAccessToken; generateDid(params: IGenerateDid): Promise; + registerDid(params: IRegister): Promise<{ + didDocument: Did; + transactionHash: string; + }>; + resolveDid(params: { + did: string; + }): Promise; } //# sourceMappingURL=did.service.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/services/did/did.service.d.ts.map b/build/src/ssiApi/services/did/did.service.d.ts.map index 54207fb..95e077d 100644 --- a/build/src/ssiApi/services/did/did.service.d.ts.map +++ b/build/src/ssiApi/services/did/did.service.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"did.service.d.ts","sourceRoot":"","sources":["../../../../../src/ssiApi/services/did/did.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAGtC,qBAAa,GAAG;IACd,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,WAAW,CAAA;gBACP,MAAM,EAAE,MAAM;YAKZ,eAAe;IAIhB,WAAW,CAAC,MAAM,EAAE,YAAY;CAqB9C"} \ No newline at end of file +{"version":3,"file":"did.service.d.ts","sourceRoot":"","sources":["../../../../../src/ssiApi/services/did/did.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAI7D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAW,MAAM,SAAS,CAAC;AAG3D,qBAAa,GAAG;IACd,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,WAAW,CAAC;gBACR,MAAM,EAAE,MAAM;YAKZ,eAAe;IAIhB,WAAW,CAAC,MAAM,EAAE,YAAY;IA2BhC,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,GAAG,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IA4DtF,UAAU,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;CAuBvE"} \ No newline at end of file diff --git a/build/src/ssiApi/services/did/did.service.js b/build/src/ssiApi/services/did/did.service.js index c659476..7279858 100644 --- a/build/src/ssiApi/services/did/did.service.js +++ b/build/src/ssiApi/services/did/did.service.js @@ -13,6 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DID = void 0; +const IDID_1 = require("../../../did/IDID"); +const api_constant_1 = require("../../api-constant"); const apiAuth_1 = require("../../apiAuth/apiAuth"); const node_fetch_1 = __importDefault(require("node-fetch")); class DID { @@ -28,28 +30,107 @@ class DID { } generateDid(params) { return __awaiter(this, void 0, void 0, function* () { - const apiUrl = "https://api.entity.hypersign.id/api/v1/did/create"; + if (!params.namespace) { + throw new Error('HID-SSI-SDK:: Error: params.namespace is required to generate new did doc '); + } + const apiUrl = `${api_constant_1.APIENDPOINT.STUDIO_API_BASE_URL}${api_constant_1.APIENDPOINT.DID.CREATE_DID_ENDPOINT}`; const headers = { - "Content-Type": "application/json", + 'Content-Type': 'application/json', Authorization: `Bearer ${this.accessToken}`, - Origin: "https://entity.hypersign.id" }; const requestOptions = { - method: "POST", + method: 'POST', headers, - body: JSON.stringify(Object.assign({}, params)) + body: JSON.stringify(Object.assign({}, params)), }; const response = yield (0, node_fetch_1.default)(apiUrl, requestOptions); + const result = yield response.json(); + console.log(result); + // need to add scenario of checking if token is expired or not + // can be done either by directly call in studio-api and then based on error regenerate it + // or add jwt package to validate its expiry if (!response.ok) { - // need to figure out how to send correct error message as not getting exact message from studio - throw new Error('HID-SSI_SDK:: Error: Issue in generating did'); + throw new Error(`HID-SSI-SDK:: Error: ${result.message}`); } - const { metaData } = yield response.json(); + const { metaData } = result; return metaData.didDocument; }); } + registerDid(params) { + var _a, _b, _c, _d; + return __awaiter(this, void 0, void 0, function* () { + if (!params.didDocument || Object.keys(params.didDocument).length === 0) { + throw new Error('HID-SSI-SDK:: Error: params.didDocument is required to register a did'); + } + if (!params.signInfos) { + if (!params.verificationMethodId) { + throw new Error('HID-SSI-SDK:: Error: either params.verificationMethodId or params.signInfos is required to register a did'); + } + } + if (params.signInfos && params.signInfos.length === 0) { + throw new Error('HID-SSI-SDK:: Error: params.signInfos is required to register a did'); + } + if (params.signInfos && params.signInfos.length > 0) { + for (const i in params.signInfos) { + if (!params.signInfos[i].verification_method_id) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].verification_method_id is required to register a did`); + } + if (!params.signInfos[i].clientSpec) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].clientSpec is required to register a did`); + } + if (!(params.signInfos[i].clientSpec.type in IDID_1.IClientSpec)) { + throw new Error('HID-SSI-SDK:: Error: params.clientSpec is invalid'); + } + if (((_a = params.signInfos[i].clientSpec) === null || _a === void 0 ? void 0 : _a.type) === IDID_1.IClientSpec['cosmos-ADR036']) { + if (((_b = params.signInfos[i].clientSpec) === null || _b === void 0 ? void 0 : _b.adr036SignerAddress) === '' || + ((_c = params.signInfos[i].clientSpec) === null || _c === void 0 ? void 0 : _c.adr036SignerAddress) === undefined) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].adr036SignerAddress is required to register a did, when clientSpec type is${(_d = params.signInfos[i].clientSpec) === null || _d === void 0 ? void 0 : _d.type} `); + } + } + if (!params.signInfos[i].signature) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].signature is required to register a did`); + } + } + } + const apiUrl = `${api_constant_1.APIENDPOINT.STUDIO_API_BASE_URL}${api_constant_1.APIENDPOINT.DID.REGISTER_DID_ENDPOINT}`; + const headers = { + 'Content-Type': 'application/json', + Authorization: `Bearer ${this.accessToken}`, + }; + const requestOptions = { + method: 'POST', + headers, + body: JSON.stringify(Object.assign({}, params)), + }; + const response = yield (0, node_fetch_1.default)(apiUrl, requestOptions); + const result = yield response.json(); + if (!response.ok) { + throw new Error(`HID-SSI-SDK:: Error: ${result.message}`); + } + const { metaData } = result; + return { didDocument: metaData.didDocument, transactionHash: result.transactionHash }; + }); + } + resolveDid(params) { + return __awaiter(this, void 0, void 0, function* () { + if (!params.did) { + throw new Error('HID-SSI-SDK:: Error: params.did is required to resolve a did'); + } + const apiUrl = `${api_constant_1.APIENDPOINT.STUDIO_API_BASE_URL}${api_constant_1.APIENDPOINT.DID.RESOLVE_DID_ENDPOINT}/${params.did}`; + const headers = { + Authorization: `Bearer ${this.accessToken}`, + }; + const requestOptions = { + method: 'GET', + headers, + }; + const response = yield (0, node_fetch_1.default)(apiUrl, requestOptions); + const result = yield response.json(); + if (!response.ok) { + throw new Error(`HID-SSI-SDK:: Error: ${result.message}`); + } + return result; + }); + } } exports.DID = DID; -// const test = new DID("c4dae4b264f98798920ad22456c6f.acd24a3adeaed7fddf86044925d419afc252ada299b018e961ed3ac3ae2d1aaebd577eb0550c2c011fd9f51d33097d88a") -const test = new DID("586a74602fffda655f186ca9c162f.445dbab93f8b3b24501a9bdb1254de6a1528d4db306d87e2674f2277ddcc40a5b6686c4b2fe996ae11509d72eb4bb0d38"); -console.log(test, "test"); diff --git a/src/ssiApi/api-constant.ts b/src/ssiApi/api-constant.ts new file mode 100644 index 0000000..4d87aeb --- /dev/null +++ b/src/ssiApi/api-constant.ts @@ -0,0 +1,10 @@ +export const APIENDPOINT = { + STUDIO_API_BASE_URL: 'https://api.entity.hypersign.id/api/v1', + AUTH: '/app/oauth', + DID: { + CREATE_DID_ENDPOINT: '/did/create', + REGISTER_DID_ENDPOINT: '/did/register', + UPDATE_DID_ENDPOINT: '/did', + RESOLVE_DID_ENDPOINT: '/did/resolve', + }, +}; diff --git a/src/ssiApi/apiAuth/apiAuth.ts b/src/ssiApi/apiAuth/apiAuth.ts index 38befa9..546507d 100644 --- a/src/ssiApi/apiAuth/apiAuth.ts +++ b/src/ssiApi/apiAuth/apiAuth.ts @@ -1,5 +1,6 @@ import fetch from "node-fetch" import { IgenerateToken } from "./IAuth"; +import {APIENDPOINT} from "../api-constant" export class ApiAuth { private apiKey: string; constructor(apiKey) { @@ -9,21 +10,21 @@ export class ApiAuth { this.apiKey = apiKey } async generateAccessToken(): Promise { - const studioApiUrl = "https://api.entity.hypersign.id/api/v1/app/oauth" - const headers = { - "X-Api-Secret-Key": this.apiKey, - "Origin": "https://entity.hypersign.id" - } - const requestOptions = { - method: "POST", - headers, - } - const response = await fetch(studioApiUrl, requestOptions) - if (!response.ok) { - // what error to send not getting error message from api - throw new Error('HID-SSI_SDK:: Error: Unauthorized') - } - const authToken = await response.json() - return authToken + const studioApiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.AUTH}` + const headers = { + "X-Api-Secret-Key": this.apiKey, + } + const requestOptions = { + method: "POST", + headers, + } + const response = await fetch(studioApiUrl, requestOptions) + const authToken = await response.json() + if (!response.ok) { + throw new Error(`HID-SSI-SDK:: Error: ${authToken.message}`) + } + return authToken + + } } diff --git a/src/ssiApi/services/IDid.ts b/src/ssiApi/services/IDid.ts index ff55748..fe62877 100644 --- a/src/ssiApi/services/IDid.ts +++ b/src/ssiApi/services/IDid.ts @@ -1,4 +1,5 @@ -import { IKeyType, IVerificationRelationships } from "../../did/IDID"; +import { Did } from "../../../libs/generated/ssi/did"; +import { IClientSpec, IKeyType, IVerificationRelationships } from "../../did/IDID"; export interface IGenerateDid{ namespace:string; @@ -10,4 +11,25 @@ export interface IGenerateDid{ walletAddress:string, verificationRelationships:IVerificationRelationships[] } +} + +interface ClientSpec{ + type:IClientSpec; + adr036SignerAddress?:string; +} +interface SignInfo{ + verification_method_id:string; + signature: string; + clientSpec:ClientSpec +} +export interface IRegister{ + didDocument:Did; + verificationMethodId?:string; + signInfos?:Array + +} + + +export interface IUpdate extends IRegister{ + deactivate:boolean } \ No newline at end of file diff --git a/src/ssiApi/services/did/did.service.ts b/src/ssiApi/services/did/did.service.ts index f679428..f3b59f2 100644 --- a/src/ssiApi/services/did/did.service.ts +++ b/src/ssiApi/services/did/did.service.ts @@ -1,47 +1,131 @@ -import { IAuth } from "../../apiAuth/IAuth" -import { ApiAuth } from "../../apiAuth/apiAuth" -import { IGenerateDid } from "../IDid" -import fetch from "node-fetch" +import { Did } from '../../../../libs/generated/ssi/did'; +import { IClientSpec, IDIDResolve } from '../../../did/IDID'; +import { APIENDPOINT } from '../../api-constant'; +import { IAuth } from '../../apiAuth/IAuth'; +import { ApiAuth } from '../../apiAuth/apiAuth'; +import { IGenerateDid, IRegister, IUpdate } from '../IDid'; +import fetch from 'node-fetch'; export class DID { - private authService: IAuth - private accessToken + private authService: IAuth; + private accessToken; constructor(apiKey: string) { this.authService = new ApiAuth(apiKey); - this.initAccessToken() + this.initAccessToken(); } private async initAccessToken() { - const accessToken = await this.authService.generateAccessToken() - this.accessToken = accessToken.access_token + const accessToken = await this.authService.generateAccessToken(); + this.accessToken = accessToken.access_token; } public async generateDid(params: IGenerateDid) { - const apiUrl = "https://api.entity.hypersign.id/api/v1/did/create" + if (!params.namespace) { + throw new Error('HID-SSI-SDK:: Error: params.namespace is required to generate new did doc '); + } + const apiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.DID.CREATE_DID_ENDPOINT}`; const headers = { - "Content-Type": "application/json", + 'Content-Type': 'application/json', Authorization: `Bearer ${this.accessToken}`, - Origin: "https://entity.hypersign.id" - } + }; const requestOptions = { - method: "POST", + method: 'POST', headers, - body: JSON.stringify({ ...params }) - } - const response = await fetch(apiUrl, requestOptions) + body: JSON.stringify({ ...params }), + }; + const response = await fetch(apiUrl, requestOptions); + const result = await response.json(); + console.log(result); + // need to add scenario of checking if token is expired or not + // can be done either by directly call in studio-api and then based on error regenerate it + // or add jwt package to validate its expiry if (!response.ok) { - // need to figure out how to send correct error message as not getting exact message from studio - throw new Error('HID-SSI_SDK:: Error: Issue in generating did') + throw new Error(`HID-SSI-SDK:: Error: ${result.message}`); } - const { metaData } = await response.json() - return metaData.didDocument + const { metaData } = result; + return metaData.didDocument; } -} - + public async registerDid(params: IRegister): Promise<{ didDocument: Did; transactionHash: string }> { + if (!params.didDocument || Object.keys(params.didDocument).length === 0) { + throw new Error('HID-SSI-SDK:: Error: params.didDocument is required to register a did'); + } + if(!params.signInfos){ + if(!params.verificationMethodId){ + throw new Error('HID-SSI-SDK:: Error: either params.verificationMethodId or params.signInfos is required to register a did') + } + } + if (params.signInfos && params.signInfos.length === 0) { + throw new Error('HID-SSI-SDK:: Error: params.signInfos is required to register a did'); + } + if (params.signInfos && params.signInfos.length > 0) { + for (const i in params.signInfos) { + if (!params.signInfos[i].verification_method_id) { + throw new Error( + `HID-SSI-SDK:: Error: params.signInfos[${i}].verification_method_id is required to register a did` + ); + } + if (!params.signInfos[i].clientSpec) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].clientSpec is required to register a did`); + } + if (!(params.signInfos[i].clientSpec.type in IClientSpec)) { + throw new Error('HID-SSI-SDK:: Error: params.clientSpec is invalid'); + } + if (params.signInfos[i].clientSpec?.type === IClientSpec['cosmos-ADR036']) { + if ( + params.signInfos[i].clientSpec?.adr036SignerAddress === '' || + params.signInfos[i].clientSpec?.adr036SignerAddress === undefined + ) { + throw new Error( + `HID-SSI-SDK:: Error: params.signInfos[${i}].adr036SignerAddress is required to register a did, when clientSpec type is${params.signInfos[i].clientSpec?.type} ` + ); + } + } + if (!params.signInfos[i].signature) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].signature is required to register a did`); + } + } + } + const apiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.DID.REGISTER_DID_ENDPOINT}`; + const headers = { + 'Content-Type': 'application/json', + Authorization: `Bearer ${this.accessToken}`, + }; + const requestOptions = { + method: 'POST', + headers, + body: JSON.stringify({ ...params }), + }; + const response = await fetch(apiUrl, requestOptions); + const result = await response.json(); + if (!response.ok) { + throw new Error(`HID-SSI-SDK:: Error: ${result.message}`); + } + const { metaData } = result; + return { didDocument: metaData.didDocument, transactionHash: result.transactionHash }; + } + public async resolveDid(params: { did: string }): Promise { + if (!params.did) { + throw new Error('HID-SSI-SDK:: Error: params.did is required to resolve a did'); + } + const apiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.DID.RESOLVE_DID_ENDPOINT}/${params.did}`; + const headers = { + Authorization: `Bearer ${this.accessToken}`, + }; + const requestOptions = { + method: 'GET', + headers, + }; + const response = await fetch(apiUrl, requestOptions); + const result = await response.json(); + if (!response.ok) { + throw new Error(`HID-SSI-SDK:: Error: ${result.message}`); + } + return result; + } -// const test = new DID("c4dae4b264f98798920ad22456c6f.acd24a3adeaed7fddf86044925d419afc252ada299b018e961ed3ac3ae2d1aaebd577eb0550c2c011fd9f51d33097d88a") -const test = new DID("586a74602fffda655f186ca9c162f.445dbab93f8b3b24501a9bdb1254de6a1528d4db306d87e2674f2277ddcc40a5b6686c4b2fe996ae11509d72eb4bb0d38") + // public async updateDid(params:IUpdate){ -console.log(test, "test") \ No newline at end of file + // } +} From 45a5c54fa269e88174a01f835b0e7b43f5e0046c Mon Sep 17 00:00:00 2001 From: varsha766 Date: Mon, 24 Jul 2023 10:34:42 +0530 Subject: [PATCH 3/7] code prettified --- src/ssiApi/apiAuth/apiAuth.ts | 50 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/ssiApi/apiAuth/apiAuth.ts b/src/ssiApi/apiAuth/apiAuth.ts index 546507d..432475b 100644 --- a/src/ssiApi/apiAuth/apiAuth.ts +++ b/src/ssiApi/apiAuth/apiAuth.ts @@ -1,30 +1,28 @@ -import fetch from "node-fetch" -import { IgenerateToken } from "./IAuth"; -import {APIENDPOINT} from "../api-constant" +import fetch from 'node-fetch'; +import { IgenerateToken } from './IAuth'; +import { APIENDPOINT } from '../api-constant'; export class ApiAuth { - private apiKey: string; - constructor(apiKey) { - if (!apiKey || apiKey.trim() === "") { - throw new Error("HID-SSI_SDK:: Error: Please Provide apiKey") - } - this.apiKey = apiKey + private apiKey: string; + constructor(apiKey) { + if (!apiKey || apiKey.trim() === '') { + throw new Error('HID-SSI_SDK:: Error: Please Provide apiKey'); } - async generateAccessToken(): Promise { - const studioApiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.AUTH}` - const headers = { - "X-Api-Secret-Key": this.apiKey, - } - const requestOptions = { - method: "POST", - headers, - } - const response = await fetch(studioApiUrl, requestOptions) - const authToken = await response.json() - if (!response.ok) { - throw new Error(`HID-SSI-SDK:: Error: ${authToken.message}`) - } - return authToken - - + this.apiKey = apiKey; + } + async generateAccessToken(): Promise { + const studioApiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.AUTH}`; + const headers = { + 'X-Api-Secret-Key': this.apiKey, + }; + const requestOptions = { + method: 'POST', + headers, + }; + const response = await fetch(studioApiUrl, requestOptions); + const authToken = await response.json(); + if (!response.ok) { + throw new Error(`HID-SSI-SDK:: Error: ${authToken.message}`); } + return authToken; + } } From 4d2b852e8f25222eae52ed67e19214f4ac043ae4 Mon Sep 17 00:00:00 2001 From: varsha766 Date: Mon, 24 Jul 2023 10:35:35 +0530 Subject: [PATCH 4/7] added build folder --- build/src/ssiApi/apiAuth/apiAuth.d.ts | 2 +- build/src/ssiApi/apiAuth/apiAuth.d.ts.map | 2 +- build/src/ssiApi/apiAuth/apiAuth.js | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build/src/ssiApi/apiAuth/apiAuth.d.ts b/build/src/ssiApi/apiAuth/apiAuth.d.ts index ee35004..6248223 100644 --- a/build/src/ssiApi/apiAuth/apiAuth.d.ts +++ b/build/src/ssiApi/apiAuth/apiAuth.d.ts @@ -1,4 +1,4 @@ -import { IgenerateToken } from "./IAuth"; +import { IgenerateToken } from './IAuth'; export declare class ApiAuth { private apiKey; constructor(apiKey: any); diff --git a/build/src/ssiApi/apiAuth/apiAuth.d.ts.map b/build/src/ssiApi/apiAuth/apiAuth.d.ts.map index dfd5ffe..38c930e 100644 --- a/build/src/ssiApi/apiAuth/apiAuth.d.ts.map +++ b/build/src/ssiApi/apiAuth/apiAuth.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"apiAuth.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/apiAuth/apiAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,qBAAa,OAAO;IAChB,OAAO,CAAC,MAAM,CAAS;gBACX,MAAM,KAAA;IAMZ,mBAAmB,IAAI,OAAO,CAAC,cAAc,CAAC;CAkBvD"} \ No newline at end of file +{"version":3,"file":"apiAuth.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/apiAuth/apiAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAS;gBACX,MAAM,KAAA;IAMZ,mBAAmB,IAAI,OAAO,CAAC,cAAc,CAAC;CAgBrD"} \ No newline at end of file diff --git a/build/src/ssiApi/apiAuth/apiAuth.js b/build/src/ssiApi/apiAuth/apiAuth.js index b8e8e06..2f9b797 100644 --- a/build/src/ssiApi/apiAuth/apiAuth.js +++ b/build/src/ssiApi/apiAuth/apiAuth.js @@ -17,8 +17,8 @@ const node_fetch_1 = __importDefault(require("node-fetch")); const api_constant_1 = require("../api-constant"); class ApiAuth { constructor(apiKey) { - if (!apiKey || apiKey.trim() === "") { - throw new Error("HID-SSI_SDK:: Error: Please Provide apiKey"); + if (!apiKey || apiKey.trim() === '') { + throw new Error('HID-SSI_SDK:: Error: Please Provide apiKey'); } this.apiKey = apiKey; } @@ -26,10 +26,10 @@ class ApiAuth { return __awaiter(this, void 0, void 0, function* () { const studioApiUrl = `${api_constant_1.APIENDPOINT.STUDIO_API_BASE_URL}${api_constant_1.APIENDPOINT.AUTH}`; const headers = { - "X-Api-Secret-Key": this.apiKey, + 'X-Api-Secret-Key': this.apiKey, }; const requestOptions = { - method: "POST", + method: 'POST', headers, }; const response = yield (0, node_fetch_1.default)(studioApiUrl, requestOptions); From 4df010b55395f23b7a86f95aa94b974aec1bd55c Mon Sep 17 00:00:00 2001 From: varsha766 Date: Fri, 28 Jul 2023 13:43:06 +0530 Subject: [PATCH 5/7] added api for updateDid and function to refresh token --- build/src/ssiApi/apiAuth/IAuth.d.ts | 7 + build/src/ssiApi/apiAuth/IAuth.d.ts.map | 2 +- build/src/ssiApi/apiAuth/apiAuth.d.ts | 5 +- build/src/ssiApi/apiAuth/apiAuth.d.ts.map | 2 +- build/src/ssiApi/apiAuth/apiAuth.js | 27 ++++ build/src/ssiApi/services/IDid.d.ts.map | 2 +- .../src/ssiApi/services/did/did.service.d.ts | 45 ++++++- .../ssiApi/services/did/did.service.d.ts.map | 2 +- build/src/ssiApi/services/did/did.service.js | 108 ++++++++++++++- package.json | 1 + src/ssiApi/apiAuth/IAuth.ts | 5 + src/ssiApi/apiAuth/apiAuth.ts | 28 +++- src/ssiApi/services/IDid.ts | 1 - src/ssiApi/services/did/did.service.ts | 127 ++++++++++++++++-- 14 files changed, 340 insertions(+), 22 deletions(-) diff --git a/build/src/ssiApi/apiAuth/IAuth.d.ts b/build/src/ssiApi/apiAuth/IAuth.d.ts index 127231a..e3520eb 100644 --- a/build/src/ssiApi/apiAuth/IAuth.d.ts +++ b/build/src/ssiApi/apiAuth/IAuth.d.ts @@ -1,9 +1,16 @@ export interface IAuth { generateAccessToken(): Promise; + checkAndRefreshAToken(params: { + accessToken: string; + }): Promise; } export interface IgenerateToken { access_token: string; expiresIn: number; tokenType: string; } +export interface IValidateAccesstokenResp { + valid: boolean; + accessToken?: string; +} //# sourceMappingURL=IAuth.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/apiAuth/IAuth.d.ts.map b/build/src/ssiApi/apiAuth/IAuth.d.ts.map index 9335771..616c1a5 100644 --- a/build/src/ssiApi/apiAuth/IAuth.d.ts.map +++ b/build/src/ssiApi/apiAuth/IAuth.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IAuth.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/apiAuth/IAuth.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IAClB,mBAAmB,IAAG,OAAO,CAAC,cAAc,CAAC,CAAA;CAChD;AAED,MAAM,WAAW,cAAc;IAC3B,YAAY,EAAC,MAAM,CAAC;IACnB,SAAS,EAAC,MAAM,CAAC;IACjB,SAAS,EAAC,MAAM,CAAC;CACrB"} \ No newline at end of file +{"version":3,"file":"IAuth.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/apiAuth/IAuth.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IAClB,mBAAmB,IAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7C,qBAAqB,CAAC,MAAM,EAAC;QAAC,WAAW,EAAC,MAAM,CAAA;KAAC,GAAE,OAAO,CAAC,wBAAwB,CAAC,CAAA;CACvF;AAED,MAAM,WAAW,cAAc;IAC3B,YAAY,EAAC,MAAM,CAAC;IACnB,SAAS,EAAC,MAAM,CAAC;IACjB,SAAS,EAAC,MAAM,CAAC;CACrB;AACD,MAAM,WAAW,wBAAwB;IACrC,KAAK,EAAC,OAAO,CAAC;IACd,WAAW,CAAC,EAAC,MAAM,CAAA;CACtB"} \ No newline at end of file diff --git a/build/src/ssiApi/apiAuth/apiAuth.d.ts b/build/src/ssiApi/apiAuth/apiAuth.d.ts index 6248223..5157a66 100644 --- a/build/src/ssiApi/apiAuth/apiAuth.d.ts +++ b/build/src/ssiApi/apiAuth/apiAuth.d.ts @@ -1,7 +1,10 @@ -import { IgenerateToken } from './IAuth'; +import { IValidateAccesstokenResp, IgenerateToken } from './IAuth'; export declare class ApiAuth { private apiKey; constructor(apiKey: any); generateAccessToken(): Promise; + checkAndRefreshAToken(params: { + accessToken: string; + }): Promise; } //# sourceMappingURL=apiAuth.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/apiAuth/apiAuth.d.ts.map b/build/src/ssiApi/apiAuth/apiAuth.d.ts.map index 38c930e..3e322a7 100644 --- a/build/src/ssiApi/apiAuth/apiAuth.d.ts.map +++ b/build/src/ssiApi/apiAuth/apiAuth.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"apiAuth.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/apiAuth/apiAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAS;gBACX,MAAM,KAAA;IAMZ,mBAAmB,IAAI,OAAO,CAAC,cAAc,CAAC;CAgBrD"} \ No newline at end of file +{"version":3,"file":"apiAuth.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/apiAuth/apiAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGnE,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAS;gBACX,MAAM,KAAA;IAMP,mBAAmB,IAAI,OAAO,CAAC,cAAc,CAAC;IAiB9C,qBAAqB,CAAC,MAAM,EAAC;QAAC,WAAW,EAAC,MAAM,CAAA;KAAC,GAAE,OAAO,CAAC,wBAAwB,CAAC;CAiBhG"} \ No newline at end of file diff --git a/build/src/ssiApi/apiAuth/apiAuth.js b/build/src/ssiApi/apiAuth/apiAuth.js index 2f9b797..14aef5e 100644 --- a/build/src/ssiApi/apiAuth/apiAuth.js +++ b/build/src/ssiApi/apiAuth/apiAuth.js @@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiAuth = void 0; const node_fetch_1 = __importDefault(require("node-fetch")); const api_constant_1 = require("../api-constant"); +const jsonwebtoken_1 = __importDefault(require("jsonwebtoken")); class ApiAuth { constructor(apiKey) { if (!apiKey || apiKey.trim() === '') { @@ -40,5 +41,31 @@ class ApiAuth { return authToken; }); } + checkAndRefreshAToken(params) { + var _a; + return __awaiter(this, void 0, void 0, function* () { + try { + const decodeToken = jsonwebtoken_1.default.decode(params.accessToken, { complete: true }); + if (!decodeToken) { + throw new Error('HID-SSI-SDK:: Error: Token is invalid or malformed'); + } + const currentTime = Math.floor(Date.now() / 1000); + if (currentTime >= ((_a = decodeToken.payload) === null || _a === void 0 ? void 0 : _a.exp)) { + const { access_token } = yield this.generateAccessToken(); + return { valid: false, accessToken: access_token }; + } + else { + return { valid: true }; + } + } + catch (e) { + throw new Error(`HID-SSI-SDK:: Error: ${e}`); + } + }); + } } exports.ApiAuth = ApiAuth; +// const test= new ApiAuth( '286d30b3e009714679904dbb16f97.8c2cd0db41a845bae96b3837a5df159fbf0a881b4f31d5a2d5a35a5d42978e95d428dbd8e57c38d973c73c050b409b7c1') +// // const result= test.checkAndRefreshToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6ImQ2N2NkNjEyNTE2NzY0MmEyMjhjNzRjNTcwZGU5YjZjYzQ0OCIsInVzZXJJZCI6InZhcnNoYWt1bWFyaTM3MEBnbWFpbC5jb20iLCJncmFudFR5cGUiOiJjbGllbnRfY3JlZGVudGlhbHMiLCJpYXQiOjE2OTAxMjk2OTgsImV4cCI6MTY5MDE0NDA5OH0.yc7Ly8XKNmevTe8LjQTOoYFuKVDljjzZdwUfzNZXsbo") +// // const newToen= test.generateAccessToken() +// const result2= test.checkAndRefreshToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6ImQ2N2NkNjEyNTE2NzY0MmEyMjhjNzRjNTcwZGU5YjZjYzQ0OCIsInVzZXJJZCI6InZhcnNoYWt1bWFyaTM3MEBnbWFpbC5jb20iLCJncmFudFR5cGUiOiJjbGllbnRfY3JlZGVudGlhbHMiLCJpYXQiOjE2OTA1Mjc1NDQsImV4cCI6MTY5MDU0MTk0NH0.kIl2zIjuJa-keotjP5B18KM3HzTBq3T-_-vRdLqkr7w') diff --git a/build/src/ssiApi/services/IDid.d.ts.map b/build/src/ssiApi/services/IDid.d.ts.map index 7ce23b1..f7b8539 100644 --- a/build/src/ssiApi/services/IDid.d.ts.map +++ b/build/src/ssiApi/services/IDid.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"IDid.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/services/IDid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAEnF,MAAM,WAAW,YAAY;IACzB,SAAS,EAAC,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAC,MAAM,CAAC;IACzB,OAAO,CAAC,EAAC;QACL,OAAO,EAAC,QAAQ,CAAC;QACjB,OAAO,EAAC,MAAM,CAAC;QACf,SAAS,EAAC,MAAM,CAAC;QACjB,aAAa,EAAC,MAAM,CAAC;QACrB,yBAAyB,EAAC,0BAA0B,EAAE,CAAA;KACzD,CAAA;CACJ;AAED,UAAU,UAAU;IAChB,IAAI,EAAC,WAAW,CAAC;IACjB,mBAAmB,CAAC,EAAC,MAAM,CAAC;CAC/B;AACD,UAAU,QAAQ;IACd,sBAAsB,EAAC,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAC,UAAU,CAAA;CACxB;AACD,MAAM,WAAW,SAAS;IACtB,WAAW,EAAC,GAAG,CAAC;IAChB,oBAAoB,CAAC,EAAC,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;CAE7B;AAGD,MAAM,WAAW,OAAQ,SAAQ,SAAS;IACtC,UAAU,EAAC,OAAO,CAAA;CACrB"} \ No newline at end of file +{"version":3,"file":"IDid.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/services/IDid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAEnF,MAAM,WAAW,YAAY;IACzB,SAAS,EAAC,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAC,MAAM,CAAC;IACzB,OAAO,CAAC,EAAC;QACL,OAAO,EAAC,QAAQ,CAAC;QACjB,OAAO,EAAC,MAAM,CAAC;QACf,SAAS,EAAC,MAAM,CAAC;QACjB,aAAa,EAAC,MAAM,CAAC;QACrB,yBAAyB,EAAC,0BAA0B,EAAE,CAAA;KACzD,CAAA;CACJ;AAED,UAAU,UAAU;IAChB,IAAI,EAAC,WAAW,CAAC;IACjB,mBAAmB,CAAC,EAAC,MAAM,CAAC;CAC/B;AACD,UAAU,QAAQ;IACd,sBAAsB,EAAC,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAC,UAAU,CAAA;CACxB;AACD,MAAM,WAAW,SAAS;IACtB,WAAW,EAAC,GAAG,CAAC;IAChB,oBAAoB,CAAC,EAAC,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;CAE7B;AAED,MAAM,WAAW,OAAQ,SAAQ,SAAS;IACtC,UAAU,EAAC,OAAO,CAAA;CACrB"} \ No newline at end of file diff --git a/build/src/ssiApi/services/did/did.service.d.ts b/build/src/ssiApi/services/did/did.service.d.ts index 2f436ec..e91ef51 100644 --- a/build/src/ssiApi/services/did/did.service.d.ts +++ b/build/src/ssiApi/services/did/did.service.d.ts @@ -1,18 +1,59 @@ import { Did } from '../../../../libs/generated/ssi/did'; import { IDIDResolve } from '../../../did/IDID'; -import { IGenerateDid, IRegister } from '../IDid'; +import { IGenerateDid, IRegister, IUpdate } from '../IDid'; export declare class DID { private authService; private accessToken; constructor(apiKey: string); private initAccessToken; - generateDid(params: IGenerateDid): Promise; + /** + * Create a new DID Document from api + * @param + * - params.namespace : namespace of did id, Default "di:hid" + * - params.methoSpecificId : Optional, methodSpecificId (min 32 bit alphanumeric) else it will generate new random methodSpecificId or may be walletaddress + * - params.options : Optional, options for providing some extra information + * - params.options.keyType : Optional, keyType used for verification + * - params.options.chainId : Optional, chainId + * - params.options.publicKey : Optional, publicKey 'Public Key' extracted from keplr wallet + * - params.options.walletAddress : Optional, walletAdress is Checksum address from web3 wallet + * - params.options.verificationRelationships : Optional, verification relationships where you want to add your verificaiton method ids + * @returns {Promise} DidDocument object + */ + generateDid(params: IGenerateDid): Promise; + /** + * Register a new DID and Document in Hypersign blockchain - an onchain activity + * @params + * - params.didDocument : LD did document + * - params.verificationMethodId : VerificationMethodId of the document + * - params.signInfos[] : Optional, signInfos array of verificationId, signature and clientSpec + * - params.signInfos.verification_method_id : VerificationMethodId of the document + * - params.signInfos.signature : Signature for clientSpec + * - params.signInfos.clientSpec : ClientSpec + * @return {Promise} + */ registerDid(params: IRegister): Promise<{ didDocument: Did; transactionHash: string; }>; + /** + * @params + * - params.did : Did document Id + * @returns {Promise} didDocument and didDocumentMetadata + */ resolveDid(params: { did: string; }): Promise; + /** + * Update a DIDDocument in Hypersign blockchain - an onchain activity + * - params.didDocument : LD did document + * - params.verificationMethodId : VerificationMethodId of the document + * - params.deactivate : deactivate Field to check if to deactivate did or to update it + * - params.signInfos[] : Optional, signInfos array of verificationId, signature and clientSpec + * - params.signInfos.verification_method_id : VerificationMethodId of the document + * - params.signInfos.signature : Signature for clientSpec + * - params.signInfos.clientSpec : ClientSpec + * @return {Promise} + */ + updateDid(params: IUpdate): Promise; } //# sourceMappingURL=did.service.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/services/did/did.service.d.ts.map b/build/src/ssiApi/services/did/did.service.d.ts.map index 95e077d..8a25810 100644 --- a/build/src/ssiApi/services/did/did.service.d.ts.map +++ b/build/src/ssiApi/services/did/did.service.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"did.service.d.ts","sourceRoot":"","sources":["../../../../../src/ssiApi/services/did/did.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAI7D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAW,MAAM,SAAS,CAAC;AAG3D,qBAAa,GAAG;IACd,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,WAAW,CAAC;gBACR,MAAM,EAAE,MAAM;YAKZ,eAAe;IAIhB,WAAW,CAAC,MAAM,EAAE,YAAY;IA2BhC,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,GAAG,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IA4DtF,UAAU,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;CAuBvE"} \ No newline at end of file +{"version":3,"file":"did.service.d.ts","sourceRoot":"","sources":["../../../../../src/ssiApi/services/did/did.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAI7D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG3D,qBAAa,GAAG;IACd,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,WAAW,CAAC;gBACR,MAAM,EAAE,MAAM;YAKZ,eAAe;IAM7B;;;;;;;;;;;;OAYG;IACU,WAAW,CAAC,MAAM,EAAE,YAAY,GAAE,OAAO,CAAC,GAAG,CAAC;IAmC7D;;;;;;;;;;QAUI;IACW,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,GAAG,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IA2DrG;;;;OAIG;IACY,UAAU,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAmBxE;;;;;;;;;;QAUI;IAEW,SAAS,CAAC,MAAM,EAAC,OAAO;CA0DtC"} \ No newline at end of file diff --git a/build/src/ssiApi/services/did/did.service.js b/build/src/ssiApi/services/did/did.service.js index 7279858..991b171 100644 --- a/build/src/ssiApi/services/did/did.service.js +++ b/build/src/ssiApi/services/did/did.service.js @@ -26,13 +26,36 @@ class DID { return __awaiter(this, void 0, void 0, function* () { const accessToken = yield this.authService.generateAccessToken(); this.accessToken = accessToken.access_token; + const j = yield test.generateDid({ namespace: 'testnet' }); + //console.log(j, 'j'); }); } + /** + * Create a new DID Document from api + * @param + * - params.namespace : namespace of did id, Default "di:hid" + * - params.methoSpecificId : Optional, methodSpecificId (min 32 bit alphanumeric) else it will generate new random methodSpecificId or may be walletaddress + * - params.options : Optional, options for providing some extra information + * - params.options.keyType : Optional, keyType used for verification + * - params.options.chainId : Optional, chainId + * - params.options.publicKey : Optional, publicKey 'Public Key' extracted from keplr wallet + * - params.options.walletAddress : Optional, walletAdress is Checksum address from web3 wallet + * - params.options.verificationRelationships : Optional, verification relationships where you want to add your verificaiton method ids + * @returns {Promise} DidDocument object + */ generateDid(params) { return __awaiter(this, void 0, void 0, function* () { if (!params.namespace) { throw new Error('HID-SSI-SDK:: Error: params.namespace is required to generate new did doc '); } + console.log(this.accessToken); + this.accessToken = "JhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6ImQ2N2NkNjEyNTE2NzY0MmEyMjhjNzRjNTcwZGU5YjZjYzQ0OCIsInVzZXJJZCI6InZhcnNoYWt1bWFyaTM3MEBnbWFpbC5jb20iLCJncmFudFR5cGUiOiJjbGllbnRfY3JlZGVudGlhbHMiLCJpYXQiOjE2OTAxMjk2OTgsImV4cCI6MTY5MDE0NDA5OH0.yc7Ly8XKNmevTe8LjQTOoYFuKVDljjzZdwUfzNZXsbo"; + const isAccessTokenValid = yield this.authService.checkAndRefreshAToken({ accessToken: this.accessToken }); + console.log(isAccessTokenValid); + if (!isAccessTokenValid.valid) { + console.log('inside if'); + this.accessToken = isAccessTokenValid.accessToken; + } const apiUrl = `${api_constant_1.APIENDPOINT.STUDIO_API_BASE_URL}${api_constant_1.APIENDPOINT.DID.CREATE_DID_ENDPOINT}`; const headers = { 'Content-Type': 'application/json', @@ -45,7 +68,7 @@ class DID { }; const response = yield (0, node_fetch_1.default)(apiUrl, requestOptions); const result = yield response.json(); - console.log(result); + // console.log(result); // need to add scenario of checking if token is expired or not // can be done either by directly call in studio-api and then based on error regenerate it // or add jwt package to validate its expiry @@ -56,6 +79,17 @@ class DID { return metaData.didDocument; }); } + /** + * Register a new DID and Document in Hypersign blockchain - an onchain activity + * @params + * - params.didDocument : LD did document + * - params.verificationMethodId : VerificationMethodId of the document + * - params.signInfos[] : Optional, signInfos array of verificationId, signature and clientSpec + * - params.signInfos.verification_method_id : VerificationMethodId of the document + * - params.signInfos.signature : Signature for clientSpec + * - params.signInfos.clientSpec : ClientSpec + * @return {Promise} + */ registerDid(params) { var _a, _b, _c, _d; return __awaiter(this, void 0, void 0, function* () { @@ -111,6 +145,11 @@ class DID { return { didDocument: metaData.didDocument, transactionHash: result.transactionHash }; }); } + /** + * @params + * - params.did : Did document Id + * @returns {Promise} didDocument and didDocumentMetadata + */ resolveDid(params) { return __awaiter(this, void 0, void 0, function* () { if (!params.did) { @@ -132,5 +171,72 @@ class DID { return result; }); } + /** + * Update a DIDDocument in Hypersign blockchain - an onchain activity + * - params.didDocument : LD did document + * - params.verificationMethodId : VerificationMethodId of the document + * - params.deactivate : deactivate Field to check if to deactivate did or to update it + * - params.signInfos[] : Optional, signInfos array of verificationId, signature and clientSpec + * - params.signInfos.verification_method_id : VerificationMethodId of the document + * - params.signInfos.signature : Signature for clientSpec + * - params.signInfos.clientSpec : ClientSpec + * @return {Promise} + */ + updateDid(params) { + var _a, _b, _c, _d; + return __awaiter(this, void 0, void 0, function* () { + if (!params.didDocument || Object.keys(params.didDocument).length === 0) { + throw new Error('HID-SSI-SDK:: Error: params.didDocument is required to update a did'); + } + if (!params.signInfos) { + if (!params.verificationMethodId) { + throw new Error('HID-SSI-SDK:: Error: either params.verificationMethodId or params.signInfos is required to update a did'); + } + } + if (params.signInfos && params.signInfos.length === 0) { + throw new Error('HID-SSI-SDK:: Error: params.signInfos is required to update a did'); + } + if (params.signInfos && params.signInfos.length > 0) { + for (const i in params.signInfos) { + if (!params.signInfos[i].verification_method_id) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].verification_method_id is required to update a did`); + } + if (!params.signInfos[i].clientSpec) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].clientSpec is required to update a did`); + } + if (!(params.signInfos[i].clientSpec.type in IDID_1.IClientSpec)) { + throw new Error('HID-SSI-SDK:: Error: params.clientSpec is invalid'); + } + if (((_a = params.signInfos[i].clientSpec) === null || _a === void 0 ? void 0 : _a.type) === IDID_1.IClientSpec['cosmos-ADR036']) { + if (((_b = params.signInfos[i].clientSpec) === null || _b === void 0 ? void 0 : _b.adr036SignerAddress) === '' || + ((_c = params.signInfos[i].clientSpec) === null || _c === void 0 ? void 0 : _c.adr036SignerAddress) === undefined) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].adr036SignerAddress is required to register a did, when clientSpec type is${(_d = params.signInfos[i].clientSpec) === null || _d === void 0 ? void 0 : _d.type} `); + } + } + if (!params.signInfos[i].signature) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].signature is required to register a did`); + } + } + } + const apiUrl = `${api_constant_1.APIENDPOINT.STUDIO_API_BASE_URL}${api_constant_1.APIENDPOINT.DID.UPDATE_DID_ENDPOINT}`; + const headers = { + 'Content-Type': "application/json", + Authorization: `Bearer ${this.accessToken}` + }; + const requestOptions = { + method: "PUT", + headers, + body: JSON.stringify(Object.assign({}, params)) + }; + const response = yield (0, node_fetch_1.default)(apiUrl, requestOptions); + const result = yield response.json(); + if (!response.ok) { + throw new Error(`HID-SSI-SDK:: Error: ${result.message}`); + } + return result; + }); + } } exports.DID = DID; +const test = new DID('286d30b3e009714679904dbb16f97.8c2cd0db41a845bae96b3837a5df159fbf0a881b4f31d5a2d5a35a5d42978e95d428dbd8e57c38d973c73c050b409b7c1'); +console.log(test, 'test'); diff --git a/package.json b/package.json index 97957e8..8f93c70 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "jcs": "github:hypersign-protocol/JCS", "jsonld": "^3.1.1", "jsonld-signatures": "^9.3.1", + "jsonwebtoken": "^9.0.1", "node-fetch": "^2.6.1", "protobufjs": "^6.11.2", "uuid": "^8.3.0", diff --git a/src/ssiApi/apiAuth/IAuth.ts b/src/ssiApi/apiAuth/IAuth.ts index 01f0feb..2beb8f1 100644 --- a/src/ssiApi/apiAuth/IAuth.ts +++ b/src/ssiApi/apiAuth/IAuth.ts @@ -1,9 +1,14 @@ export interface IAuth{ generateAccessToken():Promise + checkAndRefreshAToken(params:{accessToken:string}):Promise } export interface IgenerateToken{ access_token:string; expiresIn:number; tokenType:string; +} +export interface IValidateAccesstokenResp{ + valid:boolean; + accessToken?:string } \ No newline at end of file diff --git a/src/ssiApi/apiAuth/apiAuth.ts b/src/ssiApi/apiAuth/apiAuth.ts index 432475b..e0f9691 100644 --- a/src/ssiApi/apiAuth/apiAuth.ts +++ b/src/ssiApi/apiAuth/apiAuth.ts @@ -1,6 +1,7 @@ import fetch from 'node-fetch'; -import { IgenerateToken } from './IAuth'; +import { IValidateAccesstokenResp, IgenerateToken } from './IAuth'; import { APIENDPOINT } from '../api-constant'; +import jwt from "jsonwebtoken" export class ApiAuth { private apiKey: string; constructor(apiKey) { @@ -9,7 +10,7 @@ export class ApiAuth { } this.apiKey = apiKey; } - async generateAccessToken(): Promise { +public async generateAccessToken(): Promise { const studioApiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.AUTH}`; const headers = { 'X-Api-Secret-Key': this.apiKey, @@ -25,4 +26,27 @@ export class ApiAuth { } return authToken; } + +public async checkAndRefreshAToken(params:{accessToken:string}):Promise{ + try{ + const decodeToken= jwt.decode(params.accessToken,{complete: true}); + if(!decodeToken){ + throw new Error('HID-SSI-SDK:: Error: Token is invalid or malformed') + } + const currentTime= Math.floor(Date.now() / 1000); + if(currentTime>=decodeToken.payload.exp){ + const {access_token}= await this.generateAccessToken() + return {valid:false,accessToken:access_token } + }else{ + return {valid:true} + } + }catch(e){ + throw new Error(`HID-SSI-SDK:: Error: ${e}`); + } + } } + +// const test= new ApiAuth( '286d30b3e009714679904dbb16f97.8c2cd0db41a845bae96b3837a5df159fbf0a881b4f31d5a2d5a35a5d42978e95d428dbd8e57c38d973c73c050b409b7c1') +// // const result= test.checkAndRefreshToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6ImQ2N2NkNjEyNTE2NzY0MmEyMjhjNzRjNTcwZGU5YjZjYzQ0OCIsInVzZXJJZCI6InZhcnNoYWt1bWFyaTM3MEBnbWFpbC5jb20iLCJncmFudFR5cGUiOiJjbGllbnRfY3JlZGVudGlhbHMiLCJpYXQiOjE2OTAxMjk2OTgsImV4cCI6MTY5MDE0NDA5OH0.yc7Ly8XKNmevTe8LjQTOoYFuKVDljjzZdwUfzNZXsbo") +// // const newToen= test.generateAccessToken() +// const result2= test.checkAndRefreshToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6ImQ2N2NkNjEyNTE2NzY0MmEyMjhjNzRjNTcwZGU5YjZjYzQ0OCIsInVzZXJJZCI6InZhcnNoYWt1bWFyaTM3MEBnbWFpbC5jb20iLCJncmFudFR5cGUiOiJjbGllbnRfY3JlZGVudGlhbHMiLCJpYXQiOjE2OTA1Mjc1NDQsImV4cCI6MTY5MDU0MTk0NH0.kIl2zIjuJa-keotjP5B18KM3HzTBq3T-_-vRdLqkr7w') diff --git a/src/ssiApi/services/IDid.ts b/src/ssiApi/services/IDid.ts index fe62877..c393456 100644 --- a/src/ssiApi/services/IDid.ts +++ b/src/ssiApi/services/IDid.ts @@ -29,7 +29,6 @@ export interface IRegister{ } - export interface IUpdate extends IRegister{ deactivate:boolean } \ No newline at end of file diff --git a/src/ssiApi/services/did/did.service.ts b/src/ssiApi/services/did/did.service.ts index f3b59f2..41068a0 100644 --- a/src/ssiApi/services/did/did.service.ts +++ b/src/ssiApi/services/did/did.service.ts @@ -1,7 +1,7 @@ import { Did } from '../../../../libs/generated/ssi/did'; import { IClientSpec, IDIDResolve } from '../../../did/IDID'; import { APIENDPOINT } from '../../api-constant'; -import { IAuth } from '../../apiAuth/IAuth'; +import { IAuth, IValidateAccesstokenResp } from '../../apiAuth/IAuth'; import { ApiAuth } from '../../apiAuth/apiAuth'; import { IGenerateDid, IRegister, IUpdate } from '../IDid'; import fetch from 'node-fetch'; @@ -18,10 +18,27 @@ export class DID { const accessToken = await this.authService.generateAccessToken(); this.accessToken = accessToken.access_token; } - public async generateDid(params: IGenerateDid) { + /** + * Create a new DID Document from api + * @param + * - params.namespace : namespace of did id, Default "di:hid" + * - params.methoSpecificId : Optional, methodSpecificId (min 32 bit alphanumeric) else it will generate new random methodSpecificId or may be walletaddress + * - params.options : Optional, options for providing some extra information + * - params.options.keyType : Optional, keyType used for verification + * - params.options.chainId : Optional, chainId + * - params.options.publicKey : Optional, publicKey 'Public Key' extracted from keplr wallet + * - params.options.walletAddress : Optional, walletAdress is Checksum address from web3 wallet + * - params.options.verificationRelationships : Optional, verification relationships where you want to add your verificaiton method ids + * @returns {Promise} DidDocument object + */ + public async generateDid(params: IGenerateDid):Promise { if (!params.namespace) { throw new Error('HID-SSI-SDK:: Error: params.namespace is required to generate new did doc '); } + const isAccessTokenValid:IValidateAccesstokenResp= await this.authService.checkAndRefreshAToken({accessToken:this.accessToken}) + if(!isAccessTokenValid.valid){ + this.accessToken=isAccessTokenValid.accessToken + } const apiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.DID.CREATE_DID_ENDPOINT}`; const headers = { 'Content-Type': 'application/json', @@ -34,17 +51,23 @@ export class DID { }; const response = await fetch(apiUrl, requestOptions); const result = await response.json(); - console.log(result); - // need to add scenario of checking if token is expired or not - // can be done either by directly call in studio-api and then based on error regenerate it - // or add jwt package to validate its expiry if (!response.ok) { throw new Error(`HID-SSI-SDK:: Error: ${result.message}`); } const { metaData } = result; return metaData.didDocument; } - +/** + * Register a new DID and Document in Hypersign blockchain - an onchain activity + * @params + * - params.didDocument : LD did document + * - params.verificationMethodId : VerificationMethodId of the document + * - params.signInfos[] : Optional, signInfos array of verificationId, signature and clientSpec + * - params.signInfos.verification_method_id : VerificationMethodId of the document + * - params.signInfos.signature : Signature for clientSpec + * - params.signInfos.clientSpec : ClientSpec + * @return {Promise} + */ public async registerDid(params: IRegister): Promise<{ didDocument: Did; transactionHash: string }> { if (!params.didDocument || Object.keys(params.didDocument).length === 0) { throw new Error('HID-SSI-SDK:: Error: params.didDocument is required to register a did'); @@ -86,6 +109,10 @@ export class DID { } } } + const isAccessTokenValid:IValidateAccesstokenResp= await this.authService.checkAndRefreshAToken({accessToken:this.accessToken}) + if(!isAccessTokenValid.valid){ + this.accessToken=isAccessTokenValid.accessToken + } const apiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.DID.REGISTER_DID_ENDPOINT}`; const headers = { 'Content-Type': 'application/json', @@ -104,11 +131,19 @@ export class DID { const { metaData } = result; return { didDocument: metaData.didDocument, transactionHash: result.transactionHash }; } - +/** + * @params + * - params.did : Did document Id + * @returns {Promise} didDocument and didDocumentMetadata + */ public async resolveDid(params: { did: string }): Promise { if (!params.did) { throw new Error('HID-SSI-SDK:: Error: params.did is required to resolve a did'); } + const isAccessTokenValid:IValidateAccesstokenResp= await this.authService.checkAndRefreshAToken({accessToken:this.accessToken}) + if(!isAccessTokenValid.valid){ + this.accessToken=isAccessTokenValid.accessToken + } const apiUrl = `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.DID.RESOLVE_DID_ENDPOINT}/${params.did}`; const headers = { Authorization: `Bearer ${this.accessToken}`, @@ -124,8 +159,78 @@ export class DID { } return result; } +/** + * Update a DIDDocument in Hypersign blockchain - an onchain activity + * - params.didDocument : LD did document + * - params.verificationMethodId : VerificationMethodId of the document + * - params.deactivate : deactivate Field to check if to deactivate did or to update it + * - params.signInfos[] : Optional, signInfos array of verificationId, signature and clientSpec + * - params.signInfos.verification_method_id : VerificationMethodId of the document + * - params.signInfos.signature : Signature for clientSpec + * - params.signInfos.clientSpec : ClientSpec + * @return {Promise} + */ - // public async updateDid(params:IUpdate){ + public async updateDid(params:IUpdate){ + if (!params.didDocument || Object.keys(params.didDocument).length === 0) { + throw new Error('HID-SSI-SDK:: Error: params.didDocument is required to update a did'); + } + if(!params.signInfos){ + if(!params.verificationMethodId){ + throw new Error('HID-SSI-SDK:: Error: either params.verificationMethodId or params.signInfos is required to update a did') + } + } + if (params.signInfos && params.signInfos.length === 0) { + throw new Error('HID-SSI-SDK:: Error: params.signInfos is required to update a did'); + } + if (params.signInfos && params.signInfos.length > 0) { + for (const i in params.signInfos) { + if (!params.signInfos[i].verification_method_id) { + throw new Error( + `HID-SSI-SDK:: Error: params.signInfos[${i}].verification_method_id is required to update a did` + ); + } + if (!params.signInfos[i].clientSpec) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].clientSpec is required to update a did`); + } + if (!(params.signInfos[i].clientSpec.type in IClientSpec)) { + throw new Error('HID-SSI-SDK:: Error: params.clientSpec is invalid'); + } + if (params.signInfos[i].clientSpec?.type === IClientSpec['cosmos-ADR036']) { + if ( + params.signInfos[i].clientSpec?.adr036SignerAddress === '' || + params.signInfos[i].clientSpec?.adr036SignerAddress === undefined + ) { + throw new Error( + `HID-SSI-SDK:: Error: params.signInfos[${i}].adr036SignerAddress is required to register a did, when clientSpec type is${params.signInfos[i].clientSpec?.type} ` + ); + } + } - // } -} + if (!params.signInfos[i].signature) { + throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].signature is required to register a did`); + } + } + } + const isAccessTokenValid:IValidateAccesstokenResp= await this.authService.checkAndRefreshAToken({accessToken:this.accessToken}) + if(!isAccessTokenValid.valid){ + this.accessToken=isAccessTokenValid.accessToken + } + const apiUrl= `${APIENDPOINT.STUDIO_API_BASE_URL}${APIENDPOINT.DID.UPDATE_DID_ENDPOINT}` + const headers={ + 'Content-Type':"application/json", + Authorization:`Bearer ${this.accessToken}` + } + const requestOptions={ + method:"PUT", + headers, + body:JSON.stringify({...params}) + } + const response= await fetch(apiUrl, requestOptions); + const result= await response.json(); + if(!response.ok){ + throw new Error(`HID-SSI-SDK:: Error: ${result.message}`) + } + return result + } +} \ No newline at end of file From b361d944a74b15e854ede827c4a1fe5e07151079 Mon Sep 17 00:00:00 2001 From: varsha766 Date: Fri, 28 Jul 2023 13:46:46 +0530 Subject: [PATCH 6/7] build file changes --- build/src/ssiApi/apiAuth/apiAuth.js | 3 +-- .../ssiApi/services/did/did.service.d.ts.map | 2 +- build/src/ssiApi/services/did/did.service.js | 24 +++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/build/src/ssiApi/apiAuth/apiAuth.js b/build/src/ssiApi/apiAuth/apiAuth.js index 14aef5e..e150eda 100644 --- a/build/src/ssiApi/apiAuth/apiAuth.js +++ b/build/src/ssiApi/apiAuth/apiAuth.js @@ -42,7 +42,6 @@ class ApiAuth { }); } checkAndRefreshAToken(params) { - var _a; return __awaiter(this, void 0, void 0, function* () { try { const decodeToken = jsonwebtoken_1.default.decode(params.accessToken, { complete: true }); @@ -50,7 +49,7 @@ class ApiAuth { throw new Error('HID-SSI-SDK:: Error: Token is invalid or malformed'); } const currentTime = Math.floor(Date.now() / 1000); - if (currentTime >= ((_a = decodeToken.payload) === null || _a === void 0 ? void 0 : _a.exp)) { + if (currentTime >= decodeToken.payload.exp) { const { access_token } = yield this.generateAccessToken(); return { valid: false, accessToken: access_token }; } diff --git a/build/src/ssiApi/services/did/did.service.d.ts.map b/build/src/ssiApi/services/did/did.service.d.ts.map index 8a25810..b20b677 100644 --- a/build/src/ssiApi/services/did/did.service.d.ts.map +++ b/build/src/ssiApi/services/did/did.service.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"did.service.d.ts","sourceRoot":"","sources":["../../../../../src/ssiApi/services/did/did.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAI7D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG3D,qBAAa,GAAG;IACd,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,WAAW,CAAC;gBACR,MAAM,EAAE,MAAM;YAKZ,eAAe;IAM7B;;;;;;;;;;;;OAYG;IACU,WAAW,CAAC,MAAM,EAAE,YAAY,GAAE,OAAO,CAAC,GAAG,CAAC;IAmC7D;;;;;;;;;;QAUI;IACW,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,GAAG,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IA2DrG;;;;OAIG;IACY,UAAU,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAmBxE;;;;;;;;;;QAUI;IAEW,SAAS,CAAC,MAAM,EAAC,OAAO;CA0DtC"} \ No newline at end of file +{"version":3,"file":"did.service.d.ts","sourceRoot":"","sources":["../../../../../src/ssiApi/services/did/did.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAI7D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG3D,qBAAa,GAAG;IACd,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,WAAW,CAAC;gBACR,MAAM,EAAE,MAAM;YAKZ,eAAe;IAI7B;;;;;;;;;;;;OAYG;IACU,WAAW,CAAC,MAAM,EAAE,YAAY,GAAE,OAAO,CAAC,GAAG,CAAC;IA0B7D;;;;;;;;;;QAUI;IACW,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,GAAG,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IA+DrG;;;;OAIG;IACY,UAAU,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAuBxE;;;;;;;;;;QAUI;IAEW,SAAS,CAAC,MAAM,EAAC,OAAO;CA8DtC"} \ No newline at end of file diff --git a/build/src/ssiApi/services/did/did.service.js b/build/src/ssiApi/services/did/did.service.js index 991b171..59637e9 100644 --- a/build/src/ssiApi/services/did/did.service.js +++ b/build/src/ssiApi/services/did/did.service.js @@ -26,8 +26,6 @@ class DID { return __awaiter(this, void 0, void 0, function* () { const accessToken = yield this.authService.generateAccessToken(); this.accessToken = accessToken.access_token; - const j = yield test.generateDid({ namespace: 'testnet' }); - //console.log(j, 'j'); }); } /** @@ -48,12 +46,8 @@ class DID { if (!params.namespace) { throw new Error('HID-SSI-SDK:: Error: params.namespace is required to generate new did doc '); } - console.log(this.accessToken); - this.accessToken = "JhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6ImQ2N2NkNjEyNTE2NzY0MmEyMjhjNzRjNTcwZGU5YjZjYzQ0OCIsInVzZXJJZCI6InZhcnNoYWt1bWFyaTM3MEBnbWFpbC5jb20iLCJncmFudFR5cGUiOiJjbGllbnRfY3JlZGVudGlhbHMiLCJpYXQiOjE2OTAxMjk2OTgsImV4cCI6MTY5MDE0NDA5OH0.yc7Ly8XKNmevTe8LjQTOoYFuKVDljjzZdwUfzNZXsbo"; const isAccessTokenValid = yield this.authService.checkAndRefreshAToken({ accessToken: this.accessToken }); - console.log(isAccessTokenValid); if (!isAccessTokenValid.valid) { - console.log('inside if'); this.accessToken = isAccessTokenValid.accessToken; } const apiUrl = `${api_constant_1.APIENDPOINT.STUDIO_API_BASE_URL}${api_constant_1.APIENDPOINT.DID.CREATE_DID_ENDPOINT}`; @@ -68,10 +62,6 @@ class DID { }; const response = yield (0, node_fetch_1.default)(apiUrl, requestOptions); const result = yield response.json(); - // console.log(result); - // need to add scenario of checking if token is expired or not - // can be done either by directly call in studio-api and then based on error regenerate it - // or add jwt package to validate its expiry if (!response.ok) { throw new Error(`HID-SSI-SDK:: Error: ${result.message}`); } @@ -126,6 +116,10 @@ class DID { } } } + const isAccessTokenValid = yield this.authService.checkAndRefreshAToken({ accessToken: this.accessToken }); + if (!isAccessTokenValid.valid) { + this.accessToken = isAccessTokenValid.accessToken; + } const apiUrl = `${api_constant_1.APIENDPOINT.STUDIO_API_BASE_URL}${api_constant_1.APIENDPOINT.DID.REGISTER_DID_ENDPOINT}`; const headers = { 'Content-Type': 'application/json', @@ -155,6 +149,10 @@ class DID { if (!params.did) { throw new Error('HID-SSI-SDK:: Error: params.did is required to resolve a did'); } + const isAccessTokenValid = yield this.authService.checkAndRefreshAToken({ accessToken: this.accessToken }); + if (!isAccessTokenValid.valid) { + this.accessToken = isAccessTokenValid.accessToken; + } const apiUrl = `${api_constant_1.APIENDPOINT.STUDIO_API_BASE_URL}${api_constant_1.APIENDPOINT.DID.RESOLVE_DID_ENDPOINT}/${params.did}`; const headers = { Authorization: `Bearer ${this.accessToken}`, @@ -218,6 +216,10 @@ class DID { } } } + const isAccessTokenValid = yield this.authService.checkAndRefreshAToken({ accessToken: this.accessToken }); + if (!isAccessTokenValid.valid) { + this.accessToken = isAccessTokenValid.accessToken; + } const apiUrl = `${api_constant_1.APIENDPOINT.STUDIO_API_BASE_URL}${api_constant_1.APIENDPOINT.DID.UPDATE_DID_ENDPOINT}`; const headers = { 'Content-Type': "application/json", @@ -238,5 +240,3 @@ class DID { } } exports.DID = DID; -const test = new DID('286d30b3e009714679904dbb16f97.8c2cd0db41a845bae96b3837a5df159fbf0a881b4f31d5a2d5a35a5d42978e95d428dbd8e57c38d973c73c050b409b7c1'); -console.log(test, 'test'); From 352649e7924df3531382bee87d21c9a029f03ec5 Mon Sep 17 00:00:00 2001 From: varsha766 Date: Fri, 28 Jul 2023 15:24:54 +0530 Subject: [PATCH 7/7] exported class DidApi and added interface for DidApi class --- build/src/index.d.ts | 8 +- build/src/index.d.ts.map | 2 +- build/src/index.js | 16 +-- build/src/ssiApi/services/IDid.d.ts.map | 1 - build/src/ssiApi/services/{ => did}/IDid.d.ts | 22 +++- build/src/ssiApi/services/did/IDid.d.ts.map | 1 + build/src/ssiApi/services/{ => did}/IDid.js | 0 .../src/ssiApi/services/did/did.service.d.ts | 8 +- .../ssiApi/services/did/did.service.d.ts.map | 2 +- build/src/ssiApi/services/did/did.service.js | 8 +- src/index.ts | 100 ++++++++++-------- src/ssiApi/services/{ => did}/IDid.ts | 16 ++- src/ssiApi/services/did/did.service.ts | 9 +- 13 files changed, 117 insertions(+), 76 deletions(-) delete mode 100644 build/src/ssiApi/services/IDid.d.ts.map rename build/src/ssiApi/services/{ => did}/IDid.d.ts (53%) create mode 100644 build/src/ssiApi/services/did/IDid.d.ts.map rename build/src/ssiApi/services/{ => did}/IDid.js (100%) rename src/ssiApi/services/{ => did}/IDid.ts (54%) diff --git a/build/src/index.d.ts b/build/src/index.d.ts index d5ddd86..3a26329 100644 --- a/build/src/index.d.ts +++ b/build/src/index.d.ts @@ -2,23 +2,27 @@ import HypersignDID from './did/did'; import HypersignVerifiableCredential from './credential/vc'; import HypersignVerifiablePresentation from './presentation/vp'; import HypersignSchema from './schema/schema'; -import { OfflineSigner } from "@cosmjs/proto-signing"; +import { OfflineSigner } from '@cosmjs/proto-signing'; +import DidApi from './ssiApi/services/did/did.service'; declare class HypersignSSISdk { did: HypersignDID; vc: HypersignVerifiableCredential; vp: HypersignVerifiablePresentation; schema: HypersignSchema; + didApi: DidApi; private namespace; private signer; private nodeRpcEndpoint; private nodeRestEndpoint; + private apiKey; constructor(params: { offlineSigner: OfflineSigner; nodeRpcEndpoint?: string; nodeRestEndpoint?: string; namespace?: string; + apiKey?: string; }); init(): Promise; } -export { HypersignSSISdk, HypersignDID, HypersignSchema, HypersignVerifiableCredential, HypersignVerifiablePresentation }; +export { HypersignSSISdk, HypersignDID, DidApi, HypersignSchema, HypersignVerifiableCredential, HypersignVerifiablePresentation, }; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/build/src/index.d.ts.map b/build/src/index.d.ts.map index 0b5dc68..d54845c 100644 --- a/build/src/index.d.ts.map +++ b/build/src/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,WAAW,CAAC;AACrC,OAAO,6BAA6B,MAAO,iBAAiB,CAAA;AAC5D,OAAO,+BAA+B,MAAO,mBAAmB,CAAA;AAChE,OAAO,eAAe,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAGtD,cAAM,eAAe;IACjB,GAAG,EAAE,YAAY,CAAC;IAClB,EAAE,EAAE,6BAA6B,CAAC;IAClC,EAAE,EAAE,+BAA+B,CAAC;IACpC,MAAM,EAAE,eAAe,CAAC;IAExB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,gBAAgB,CAAS;gBACrB,MAAM,EAAE;QAAC,aAAa,EAAE,aAAa,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAC;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAC;IAsBrH,IAAI;CAMb;AAED,OAAQ,EACJ,eAAe,EACf,YAAY,EACZ,eAAe,EACf,6BAA6B,EAC7B,+BAA+B,EAClC,CAAA"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,WAAW,CAAC;AACrC,OAAO,6BAA6B,MAAM,iBAAiB,CAAC;AAC5D,OAAO,+BAA+B,MAAM,mBAAmB,CAAC;AAChE,OAAO,eAAe,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAQ,MAAM,MAAO,mCAAmC,CAAC;AAEzD,cAAM,eAAe;IACnB,GAAG,EAAE,YAAY,CAAC;IAClB,EAAE,EAAE,6BAA6B,CAAC;IAClC,EAAE,EAAE,+BAA+B,CAAC;IACpC,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,MAAM,CAAS;gBACX,MAAM,EAAE;QAClB,aAAa,EAAE,aAAa,CAAC;QAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAqBK,IAAI;CAKX;AAED,OAAO,EACL,eAAe,EACf,YAAY,EACZ,MAAM,EACN,eAAe,EACf,6BAA6B,EAC7B,+BAA+B,GAChC,CAAC"} \ No newline at end of file diff --git a/build/src/index.js b/build/src/index.js index 52bfed7..dda345a 100644 --- a/build/src/index.js +++ b/build/src/index.js @@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.HypersignVerifiablePresentation = exports.HypersignVerifiableCredential = exports.HypersignSchema = exports.HypersignDID = exports.HypersignSSISdk = void 0; +exports.HypersignVerifiablePresentation = exports.HypersignVerifiableCredential = exports.HypersignSchema = exports.DidApi = exports.HypersignDID = exports.HypersignSSISdk = void 0; const did_1 = __importDefault(require("./did/did")); exports.HypersignDID = did_1.default; const vc_1 = __importDefault(require("./credential/vc")); @@ -21,23 +21,27 @@ const vp_1 = __importDefault(require("./presentation/vp")); exports.HypersignVerifiablePresentation = vp_1.default; const schema_1 = __importDefault(require("./schema/schema")); exports.HypersignSchema = schema_1.default; +const did_service_1 = __importDefault(require("./ssiApi/services/did/did.service")); +exports.DidApi = did_service_1.default; class HypersignSSISdk { constructor(params) { - const { offlineSigner, nodeRpcEndpoint, nodeRestEndpoint, namespace } = params; + const { offlineSigner, nodeRpcEndpoint, nodeRestEndpoint, namespace, apiKey } = params; this.signer = offlineSigner; - this.nodeRpcEndpoint = nodeRpcEndpoint ? nodeRpcEndpoint : "MAIN"; - this.nodeRestEndpoint = nodeRestEndpoint ? nodeRestEndpoint : ""; - this.namespace = namespace ? namespace : ""; + this.nodeRpcEndpoint = nodeRpcEndpoint ? nodeRpcEndpoint : 'MAIN'; + this.nodeRestEndpoint = nodeRestEndpoint ? nodeRestEndpoint : ''; + this.namespace = namespace ? namespace : ''; + this.apiKey = apiKey ? apiKey : ''; const constructorParams = { offlineSigner: this.signer, nodeRpcEndpoint: this.nodeRpcEndpoint, nodeRestEndpoint: this.nodeRestEndpoint, - namespace: this.namespace + namespace: this.namespace, }; this.did = new did_1.default(constructorParams); this.schema = new schema_1.default(constructorParams); this.vc = new vc_1.default(constructorParams); this.vp = new vp_1.default(constructorParams); + this.didApi = new did_service_1.default(this.apiKey); } init() { return __awaiter(this, void 0, void 0, function* () { diff --git a/build/src/ssiApi/services/IDid.d.ts.map b/build/src/ssiApi/services/IDid.d.ts.map deleted file mode 100644 index f7b8539..0000000 --- a/build/src/ssiApi/services/IDid.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"IDid.d.ts","sourceRoot":"","sources":["../../../../src/ssiApi/services/IDid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAEnF,MAAM,WAAW,YAAY;IACzB,SAAS,EAAC,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAC,MAAM,CAAC;IACzB,OAAO,CAAC,EAAC;QACL,OAAO,EAAC,QAAQ,CAAC;QACjB,OAAO,EAAC,MAAM,CAAC;QACf,SAAS,EAAC,MAAM,CAAC;QACjB,aAAa,EAAC,MAAM,CAAC;QACrB,yBAAyB,EAAC,0BAA0B,EAAE,CAAA;KACzD,CAAA;CACJ;AAED,UAAU,UAAU;IAChB,IAAI,EAAC,WAAW,CAAC;IACjB,mBAAmB,CAAC,EAAC,MAAM,CAAC;CAC/B;AACD,UAAU,QAAQ;IACd,sBAAsB,EAAC,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAC,UAAU,CAAA;CACxB;AACD,MAAM,WAAW,SAAS;IACtB,WAAW,EAAC,GAAG,CAAC;IAChB,oBAAoB,CAAC,EAAC,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;CAE7B;AAED,MAAM,WAAW,OAAQ,SAAQ,SAAS;IACtC,UAAU,EAAC,OAAO,CAAA;CACrB"} \ No newline at end of file diff --git a/build/src/ssiApi/services/IDid.d.ts b/build/src/ssiApi/services/did/IDid.d.ts similarity index 53% rename from build/src/ssiApi/services/IDid.d.ts rename to build/src/ssiApi/services/did/IDid.d.ts index 2317f69..8e84a54 100644 --- a/build/src/ssiApi/services/IDid.d.ts +++ b/build/src/ssiApi/services/did/IDid.d.ts @@ -1,5 +1,5 @@ -import { Did } from "../../../libs/generated/ssi/did"; -import { IClientSpec, IKeyType, IVerificationRelationships } from "../../did/IDID"; +import { Did } from "../../../../libs/generated/ssi/did"; +import { IClientSpec, IDIDResolve, IKeyType, IVerificationRelationships } from "../../../did/IDID"; export interface IGenerateDid { namespace: string; methodSpecificId?: string; @@ -11,11 +11,11 @@ export interface IGenerateDid { verificationRelationships: IVerificationRelationships[]; }; } -interface ClientSpec { +export interface ClientSpec { type: IClientSpec; adr036SignerAddress?: string; } -interface SignInfo { +export interface SignInfo { verification_method_id: string; signature: string; clientSpec: ClientSpec; @@ -28,5 +28,17 @@ export interface IRegister { export interface IUpdate extends IRegister { deactivate: boolean; } -export {}; +export interface IDidApi { + generateDid(params: IGenerateDid): Promise; + registerDid(params: IRegister): Promise<{ + didDocument: Did; + transactionHash: string; + }>; + resolveDid(params: { + did: string; + }): Promise; + updateDid(params: IUpdate): Promise<{ + transactionHash: string; + }>; +} //# sourceMappingURL=IDid.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/services/did/IDid.d.ts.map b/build/src/ssiApi/services/did/IDid.d.ts.map new file mode 100644 index 0000000..d273795 --- /dev/null +++ b/build/src/ssiApi/services/did/IDid.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"IDid.d.ts","sourceRoot":"","sources":["../../../../../src/ssiApi/services/did/IDid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAEnG,MAAM,WAAW,YAAY;IACzB,SAAS,EAAC,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAC,MAAM,CAAC;IACzB,OAAO,CAAC,EAAC;QACL,OAAO,EAAC,QAAQ,CAAC;QACjB,OAAO,EAAC,MAAM,CAAC;QACf,SAAS,EAAC,MAAM,CAAC;QACjB,aAAa,EAAC,MAAM,CAAC;QACrB,yBAAyB,EAAC,0BAA0B,EAAE,CAAA;KACzD,CAAA;CACJ;AAED,MAAM,WAAW,UAAU;IACvB,IAAI,EAAC,WAAW,CAAC;IACjB,mBAAmB,CAAC,EAAC,MAAM,CAAC;CAC/B;AACD,MAAM,WAAW,QAAQ;IACrB,sBAAsB,EAAC,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAC,UAAU,CAAA;CACxB;AACD,MAAM,WAAW,SAAS;IACtB,WAAW,EAAC,GAAG,CAAC;IAChB,oBAAoB,CAAC,EAAC,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;CAE7B;AAED,MAAM,WAAW,OAAQ,SAAQ,SAAS;IACtC,UAAU,EAAC,OAAO,CAAA;CACrB;AAGD,MAAM,WAAW,OAAO;IACpB,WAAW,CAAC,MAAM,EAAC,YAAY,GAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IAC7C,WAAW,CAAC,MAAM,EAAC,SAAS,GAAE,OAAO,CAAC;QAAE,WAAW,EAAE,GAAG,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACpF,UAAU,CAAC,MAAM,EAAC;QAAC,GAAG,EAAC,MAAM,CAAA;KAAC,GAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IACpD,SAAS,CAAC,MAAM,EAAC,OAAO,GAAE,OAAO,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAC,CAAC,CAAA;CAC/D"} \ No newline at end of file diff --git a/build/src/ssiApi/services/IDid.js b/build/src/ssiApi/services/did/IDid.js similarity index 100% rename from build/src/ssiApi/services/IDid.js rename to build/src/ssiApi/services/did/IDid.js diff --git a/build/src/ssiApi/services/did/did.service.d.ts b/build/src/ssiApi/services/did/did.service.d.ts index e91ef51..870c82b 100644 --- a/build/src/ssiApi/services/did/did.service.d.ts +++ b/build/src/ssiApi/services/did/did.service.d.ts @@ -1,7 +1,7 @@ import { Did } from '../../../../libs/generated/ssi/did'; import { IDIDResolve } from '../../../did/IDID'; -import { IGenerateDid, IRegister, IUpdate } from '../IDid'; -export declare class DID { +import { IDidApi, IGenerateDid, IRegister, IUpdate } from './IDid'; +export default class DidApi implements IDidApi { private authService; private accessToken; constructor(apiKey: string); @@ -54,6 +54,8 @@ export declare class DID { * - params.signInfos.clientSpec : ClientSpec * @return {Promise} */ - updateDid(params: IUpdate): Promise; + updateDid(params: IUpdate): Promise<{ + transactionHash: string; + }>; } //# sourceMappingURL=did.service.d.ts.map \ No newline at end of file diff --git a/build/src/ssiApi/services/did/did.service.d.ts.map b/build/src/ssiApi/services/did/did.service.d.ts.map index b20b677..6091dcf 100644 --- a/build/src/ssiApi/services/did/did.service.d.ts.map +++ b/build/src/ssiApi/services/did/did.service.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"did.service.d.ts","sourceRoot":"","sources":["../../../../../src/ssiApi/services/did/did.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAI7D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG3D,qBAAa,GAAG;IACd,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,WAAW,CAAC;gBACR,MAAM,EAAE,MAAM;YAKZ,eAAe;IAI7B;;;;;;;;;;;;OAYG;IACU,WAAW,CAAC,MAAM,EAAE,YAAY,GAAE,OAAO,CAAC,GAAG,CAAC;IA0B7D;;;;;;;;;;QAUI;IACW,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,GAAG,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IA+DrG;;;;OAIG;IACY,UAAU,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAuBxE;;;;;;;;;;QAUI;IAEW,SAAS,CAAC,MAAM,EAAC,OAAO;CA8DtC"} \ No newline at end of file +{"version":3,"file":"did.service.d.ts","sourceRoot":"","sources":["../../../../../src/ssiApi/services/did/did.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAI7D,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGnE,MAAM,CAAC,OAAO,OAAO,MAAO,YAAW,OAAO;IAC5C,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,WAAW,CAAC;gBACR,MAAM,EAAE,MAAM;YAQZ,eAAe;IAI7B;;;;;;;;;;;;OAYG;IACU,WAAW,CAAC,MAAM,EAAE,YAAY,GAAE,OAAO,CAAC,GAAG,CAAC;IA0B7D;;;;;;;;;;QAUI;IACW,WAAW,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,GAAG,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IA+DrG;;;;OAIG;IACY,UAAU,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAuBxE;;;;;;;;;;QAUI;IAEW,SAAS,CAAC,MAAM,EAAC,OAAO,GAAE,OAAO,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAC,CAAC;CA8D1E"} \ No newline at end of file diff --git a/build/src/ssiApi/services/did/did.service.js b/build/src/ssiApi/services/did/did.service.js index 59637e9..6011b2f 100644 --- a/build/src/ssiApi/services/did/did.service.js +++ b/build/src/ssiApi/services/did/did.service.js @@ -12,13 +12,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.DID = void 0; const IDID_1 = require("../../../did/IDID"); const api_constant_1 = require("../../api-constant"); const apiAuth_1 = require("../../apiAuth/apiAuth"); const node_fetch_1 = __importDefault(require("node-fetch")); -class DID { +class DidApi { constructor(apiKey) { + if (!apiKey || apiKey.trim() === '') { + throw new Error('HID-SSI_SDK:: Error: Please Provide apiKey'); + } this.authService = new apiAuth_1.ApiAuth(apiKey); this.initAccessToken(); } @@ -239,4 +241,4 @@ class DID { }); } } -exports.DID = DID; +exports.default = DidApi; diff --git a/src/index.ts b/src/index.ts index f94932c..b201307 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,54 +1,60 @@ import HypersignDID from './did/did'; -import HypersignVerifiableCredential from './credential/vc' -import HypersignVerifiablePresentation from './presentation/vp' +import HypersignVerifiableCredential from './credential/vc'; +import HypersignVerifiablePresentation from './presentation/vp'; import HypersignSchema from './schema/schema'; -import { OfflineSigner } from "@cosmjs/proto-signing"; +import { OfflineSigner } from '@cosmjs/proto-signing'; +import DidApi from './ssiApi/services/did/did.service'; +class HypersignSSISdk { + did: HypersignDID; + vc: HypersignVerifiableCredential; + vp: HypersignVerifiablePresentation; + schema: HypersignSchema; + didApi: DidApi; + private namespace: string; + private signer: OfflineSigner; + private nodeRpcEndpoint: string; // http://localhost:26657 | 'TEST' | 'MAIN' + private nodeRestEndpoint: string; // "" | http://localhost:1317 + private apiKey: string; + constructor(params: { + offlineSigner: OfflineSigner; + nodeRpcEndpoint?: string; + nodeRestEndpoint?: string; + namespace?: string; + apiKey?: string; + }) { + const { offlineSigner, nodeRpcEndpoint, nodeRestEndpoint, namespace, apiKey } = params; + this.signer = offlineSigner; + this.nodeRpcEndpoint = nodeRpcEndpoint ? nodeRpcEndpoint : 'MAIN'; + this.nodeRestEndpoint = nodeRestEndpoint ? nodeRestEndpoint : ''; + this.namespace = namespace ? namespace : ''; + this.apiKey = apiKey ? apiKey : ''; + const constructorParams = { + offlineSigner: this.signer, + nodeRpcEndpoint: this.nodeRpcEndpoint, + nodeRestEndpoint: this.nodeRestEndpoint, + namespace: this.namespace, + }; -class HypersignSSISdk{ - did: HypersignDID; - vc: HypersignVerifiableCredential; - vp: HypersignVerifiablePresentation; - schema: HypersignSchema; - - private namespace: string; - private signer: OfflineSigner; - private nodeRpcEndpoint: string; // http://localhost:26657 | 'TEST' | 'MAIN' - private nodeRestEndpoint: string; // "" | http://localhost:1317 - constructor(params: {offlineSigner: OfflineSigner, nodeRpcEndpoint?: string, nodeRestEndpoint?: string, namespace?: string}){ - - const { offlineSigner, nodeRpcEndpoint, nodeRestEndpoint, namespace } = params; - this.signer = offlineSigner; - this.nodeRpcEndpoint = nodeRpcEndpoint ? nodeRpcEndpoint : "MAIN"; - this.nodeRestEndpoint = nodeRestEndpoint ? nodeRestEndpoint : ""; - this.namespace = namespace? namespace: ""; - - const constructorParams = { - offlineSigner: this.signer, - nodeRpcEndpoint:this.nodeRpcEndpoint, - nodeRestEndpoint: this.nodeRestEndpoint, - namespace: this.namespace - } - - this.did = new HypersignDID(constructorParams); - this.schema = new HypersignSchema(constructorParams); - this.vc = new HypersignVerifiableCredential(constructorParams); - this.vp = new HypersignVerifiablePresentation(constructorParams); - - } - - async init(){ - await this.did.init() - await this.schema.init() - await this.vc.init() - } + this.did = new HypersignDID(constructorParams); + this.schema = new HypersignSchema(constructorParams); + this.vc = new HypersignVerifiableCredential(constructorParams); + this.vp = new HypersignVerifiablePresentation(constructorParams); + this.didApi = new DidApi(this.apiKey); + } + async init() { + await this.did.init(); + await this.schema.init(); + await this.vc.init(); + } } -export { - HypersignSSISdk, - HypersignDID, - HypersignSchema, - HypersignVerifiableCredential, - HypersignVerifiablePresentation -} \ No newline at end of file +export { + HypersignSSISdk, + HypersignDID, + DidApi, + HypersignSchema, + HypersignVerifiableCredential, + HypersignVerifiablePresentation, +}; diff --git a/src/ssiApi/services/IDid.ts b/src/ssiApi/services/did/IDid.ts similarity index 54% rename from src/ssiApi/services/IDid.ts rename to src/ssiApi/services/did/IDid.ts index c393456..18756bd 100644 --- a/src/ssiApi/services/IDid.ts +++ b/src/ssiApi/services/did/IDid.ts @@ -1,5 +1,5 @@ -import { Did } from "../../../libs/generated/ssi/did"; -import { IClientSpec, IKeyType, IVerificationRelationships } from "../../did/IDID"; +import { Did } from "../../../../libs/generated/ssi/did"; +import { IClientSpec, IDIDResolve, IKeyType, IVerificationRelationships } from "../../../did/IDID"; export interface IGenerateDid{ namespace:string; @@ -13,11 +13,11 @@ export interface IGenerateDid{ } } -interface ClientSpec{ +export interface ClientSpec{ type:IClientSpec; adr036SignerAddress?:string; } -interface SignInfo{ +export interface SignInfo{ verification_method_id:string; signature: string; clientSpec:ClientSpec @@ -31,4 +31,12 @@ export interface IRegister{ export interface IUpdate extends IRegister{ deactivate:boolean +} + + +export interface IDidApi{ + generateDid(params:IGenerateDid):Promise + registerDid(params:IRegister):Promise<{ didDocument: Did; transactionHash: string }> + resolveDid(params:{did:string}):Promise + updateDid(params:IUpdate):Promise<{transactionHash: string}> } \ No newline at end of file diff --git a/src/ssiApi/services/did/did.service.ts b/src/ssiApi/services/did/did.service.ts index 41068a0..77e754d 100644 --- a/src/ssiApi/services/did/did.service.ts +++ b/src/ssiApi/services/did/did.service.ts @@ -3,13 +3,16 @@ import { IClientSpec, IDIDResolve } from '../../../did/IDID'; import { APIENDPOINT } from '../../api-constant'; import { IAuth, IValidateAccesstokenResp } from '../../apiAuth/IAuth'; import { ApiAuth } from '../../apiAuth/apiAuth'; -import { IGenerateDid, IRegister, IUpdate } from '../IDid'; +import { IDidApi, IGenerateDid, IRegister, IUpdate } from './IDid'; import fetch from 'node-fetch'; -export class DID { +export default class DidApi implements IDidApi { private authService: IAuth; private accessToken; constructor(apiKey: string) { + if (!apiKey || apiKey.trim() === '') { + throw new Error('HID-SSI_SDK:: Error: Please Provide apiKey'); + } this.authService = new ApiAuth(apiKey); this.initAccessToken(); } @@ -171,7 +174,7 @@ export class DID { * @return {Promise} */ - public async updateDid(params:IUpdate){ + public async updateDid(params:IUpdate):Promise<{transactionHash: string}>{ if (!params.didDocument || Object.keys(params.didDocument).length === 0) { throw new Error('HID-SSI-SDK:: Error: params.didDocument is required to update a did'); }