Skip to content

Commit

Permalink
Merge pull request #32 from gandalf-network/staging
Browse files Browse the repository at this point in the history
Staging -> Prod [ Bug Fix ]
  • Loading branch information
TosinJs authored Apr 20, 2024
2 parents b6d7fea + e5990f6 commit 78513bc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gandalf-network/eyeofsauron",
"version": "1.0.10",
"version": "1.0.11",
"description": "",
"main": "dist/index.js",
"bin": {
Expand Down
31 changes: 10 additions & 21 deletions src/lib/plugins/custom-plugin/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,11 @@ export class GraphQLRequestVisitor extends ClientSideBaseVisitor<
this._additionalImports.push(
`import { GraphQLClient as GQLClient } from 'graphql-request';`,
);

this._additionalImports.push(
`import { GandalfErrorCode, GandalfError, handleErrors } from '../../errors.js';`,
);

if (this.config.esModules) {
this._additionalImports.push(
`import pkg from 'elliptic';`,
);
this._additionalImports.push(
`const { ec: EC } = pkg;`,
);
this._additionalImports.push(
`import { GandalfErrorCode, GandalfError, handleErrors } from '../../errors.js';`,
);
} else {
this._additionalImports.push(
`import { ec as EC } from 'elliptic';`,
);
this._additionalImports.push(
`import { GandalfErrorCode, GandalfError, handleErrors } from '../../errors';`,
);
}
if (this.config.rawRequest) {
if (this.config.documentMode !== DocumentMode.string) {
this._additionalImports.push(`import { print } from 'graphql'`);
Expand Down Expand Up @@ -203,7 +189,7 @@ export class GraphQLRequestVisitor extends ClientSideBaseVisitor<
return `${additionalExportedTypes}
${extraVariables.join('\n')}
const ec = new EC('secp256k1');
export default class Eye {
private client: GraphQLClient = new GQLClient('${WATSON_URL}');
private withWrapper: SdkFunctionWrapper = (action) => action();
Expand All @@ -217,7 +203,7 @@ export default class Eye {
}
private async signRequestBody(requestBody: any): Promise<string> {
const privateKey = Eye.generatePrivateKeyFromHex(this.privateKey)
const privateKey = await Eye.generatePrivateKeyFromHex(this.privateKey)
try {
const hash = createHash('sha256').update(JSON.stringify(requestBody)).digest();
const signature = privateKey.sign(hash);
Expand All @@ -240,8 +226,11 @@ export default class Eye {
return headers;
}
private static generatePrivateKeyFromHex(hexPrivateKey: string): EC.KeyPair {
private static async generatePrivateKeyFromHex(hexPrivateKey: string) {
try {
const ecPromise = import('elliptic').then(elliptic => elliptic.default.ec);
const EC = await ecPromise;
const ec = new EC('secp256k1');
const key = ec.keyFromPrivate(hexPrivateKey, 'hex');
return key;
} catch (error: any) {
Expand Down

0 comments on commit 78513bc

Please sign in to comment.