-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added api call for generating access token and did #98
Changes from 1 commit
23be773
29a9b4d
45a5c54
4d2b852
4df010b
b361d94
352649e
a52b2a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface IAuth { | ||
generateAccessToken(): Promise<IgenerateToken>; | ||
} | ||
export interface IgenerateToken { | ||
access_token: string; | ||
expiresIn: number; | ||
tokenType: string; | ||
} | ||
//# sourceMappingURL=IAuth.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { IgenerateToken } from "./IAuth"; | ||
export declare class ApiAuth { | ||
private apiKey; | ||
constructor(apiKey: any); | ||
generateAccessToken(): Promise<IgenerateToken>; | ||
} | ||
//# sourceMappingURL=apiAuth.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<any>; | ||
} | ||
//# sourceMappingURL=did.service.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface IAuth{ | ||
generateAccessToken():Promise<IgenerateToken> | ||
} | ||
|
||
export interface IgenerateToken{ | ||
access_token:string; | ||
expiresIn:number; | ||
tokenType:string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IgenerateToken> { | ||
const studioApiUrl = "https://api.entity.hypersign.id/api/v1/app/oauth" | ||
const headers = { | ||
"X-Api-Secret-Key": this.apiKey, | ||
"Origin": "https://entity.hypersign.id" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Origin should not also be hardcoded, I guess you need to take this in constructor params There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need of passing origin. Its working fine without passing origin also |
||
} | ||
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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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[] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this also should not be hardcoded here |
||
const headers = { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${this.accessToken}`, | ||
Origin: "https://entity.hypersign.id" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take this in constructor params |
||
} | ||
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
studioApiUrl
should not be hardcoded here, put it in configThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya i have added it in separate file now. Yet not commited