Skip to content
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

remove old v0 errors from js sdk. provide error details to the user #385

Merged
merged 10 commits into from
Feb 26, 2024
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ apps/html/index.html
apps/nodejs/main.ts
apps/react/src/app/app.tsx

storage.test.db
storage.test.db

.nx
60 changes: 29 additions & 31 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/html/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- (DO NOT EDIT!) (HTML) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-html.mjs Thu, 22 Feb 2024 05:05:54 GMT -->
<!-- (DO NOT EDIT!) (HTML) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-html.mjs Sat, 24 Feb 2024 04:18:12 GMT -->
<!DOCTYPE html>
<html lang="en">
<head>
Expand Down Expand Up @@ -62,7 +62,7 @@
</style>
</head>
<body>
(HTML) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-html.mjs Thu, 22 Feb 2024 05:05:54 GMT
(HTML) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-html.mjs Sat, 24 Feb 2024 04:18:12 GMT

<!-- ==================== ALL EXPORTED VANILLA LIBRARIES ==================== -->

Expand Down
2 changes: 1 addition & 1 deletion apps/react/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@ pre {
`,
}}
/>
(REACT) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-react.mjs Thu, 22 Feb 2024 05:05:54 GMT
(REACT) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-react.mjs Sat, 24 Feb 2024 04:18:12 GMT
<div id="root"></div>
<pre><code id="result"></code></pre>
</>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"reset:dev": "yarn tools --remove-local-dev",
"reset": "rm -rf ./dist/packages && yarn reset:dev",
"build": "yarn build:packages",
"build:packages": "yarn gen:internal-dev && yarn update:contracts && yarn tools check --no-empty-directories=true && yarn tools fixTsConfig && yarn reset && yarn tools --build --packages && yarn tools --postBuild && yarn tools --setup-local-dev && yarn postBuild:mapDepsToDist && yarn prettier && yarn gen:readme && yarn build:verify",
"build:packages": "yarn tools --remove-local-dev && rm -rf ./dist && yarn gen:internal-dev && yarn update:contracts && yarn tools check --no-empty-directories=true && yarn tools fixTsConfig && yarn tools --build --packages && yarn tools --setup-local-dev && yarn gen:readme && yarn build:verify",
"build:target": "yarn node tools/scripts/build.mjs",
"build:setupLocalDev": "yarn tools --setup-local-dev",
"build:verify": "yarn tools --verify",
Expand Down Expand Up @@ -200,9 +200,9 @@
"ts-jest": "27.1.4",
"ts-node": "10.9.1",
"typedoc": "^0.23.10",
"typescript": "~4.7.2"
"typescript": "^4.7.2"
},
"workspaces": [
"packages/*"
]
}
}
2 changes: 1 addition & 1 deletion packages/access-control-conditions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
3 changes: 2 additions & 1 deletion packages/access-control-conditions/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": []
"types": [],
"explainFiles": true
},
"include": ["**/*.ts"],
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"]
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/auth-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/bls-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/constants/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/constants/src/lib/constants/autogen_internal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last Modified: 2024-02-22 05:04:32
// Last Modified: 2024-02-24 04:15:54
// This file is auto-generated by tools/scripts/gen-internal-dev.mjs
export const INTERNAL_DEV = [
'https://167.114.17.205:443',
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
],
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
21 changes: 12 additions & 9 deletions packages/core/src/lib/lit-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,29 +929,32 @@ export class LitCore {
* @returns { void }
*
*/
_throwNodeError = (res: RejectedNodePromises): void => {
if (res.error && res.error.errorCode) {
_throwNodeError = (res: RejectedNodePromises, requestId: string): void => {
if (res.error) {
if (
(res.error.errorCode === LIT_ERROR_CODE.NODE_NOT_AUTHORIZED ||
((res.error.errorCode &&
res.error.errorCode === LIT_ERROR_CODE.NODE_NOT_AUTHORIZED) ||
res.error.errorCode === 'not_authorized') &&
this.config.alertWhenUnauthorized
) {
log(
'[Alert originally] You are not authorized to access to this content'
);
log('You are not authorized to access this content');
}

throwError({
...res.error,
message:
res.error.message ||
'You are not authorized to access to this content',
errorCode: res.error.errorCode!,
'There was an error getting the signing shares from the nodes',
errorCode: res.error.errorCode || LIT_ERROR.UNKNOWN_ERROR.code,
requestId,
} as NodeClientErrorV0 | NodeClientErrorV1);
} else {
throwError({
message: `There was an error getting the signing shares from the nodes`,
message: `There was an error getting the signing shares from the nodes. Response from the nodes: ${JSON.stringify(
res
)}`,
error: LIT_ERROR.UNKNOWN_ERROR,
requestId,
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/ecdsa-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/encryption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/lit-auth-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
},
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/lit-node-client-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
23 changes: 11 additions & 12 deletions packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ export class LitNodeClientNodeJs
getSignatures = (signedData: Array<any>, requestId: string = ''): any => {
const initialKeys = [...new Set(signedData.flatMap((i) => Object.keys(i)))];

// processing signature shares for failed or invalid contents.
// processing signature shares for failed or invalid contents. mutates the signedData object.
for (const signatureResponse of signedData) {
for (const sigName of Object.keys(signatureResponse)) {
const requiredFields = ['signatureShare'];
Expand Down Expand Up @@ -1439,10 +1439,10 @@ export class LitNodeClientNodeJs
);

throwError({
message:
'total number of valid signatures shares does not match threshold',
message: `The total number of valid signatures shares ${shares.length} does not meet the threshold of ${this.config.minNodeCount}`,
errorKind: LIT_ERROR.NO_VALID_SHARES.kind,
errorCode: LIT_ERROR.NO_VALID_SHARES.code,
requestId,
});
}

Expand Down Expand Up @@ -1601,7 +1601,7 @@ export class LitNodeClientNodeJs
params = LitNodeClientNodeJs.normalizeParams(params);

let res;
let requestId = this.getRequestId();
let requestId = '';
// -- only run on a single node
if (targetNodeRange) {
res = await this.runOnTargetedNodes(params);
Expand Down Expand Up @@ -1652,7 +1652,7 @@ export class LitNodeClientNodeJs
}
// -- case: promises rejected
if (res.success === false) {
this._throwNodeError(res as RejectedNodePromises);
this._throwNodeError(res as RejectedNodePromises, requestId);
}

// -- case: promises success (TODO: check the keys of "values")
Expand Down Expand Up @@ -1865,7 +1865,7 @@ export class LitNodeClientNodeJs

// -- case: promises rejected
if (!res.success) {
this._throwNodeError(res as RejectedNodePromises);
this._throwNodeError(res as RejectedNodePromises, requestId);
}

// -- case: promises success (TODO: check the keys of "values")
Expand Down Expand Up @@ -1994,7 +1994,6 @@ export class LitNodeClientNodeJs
}

// ========== Get Node Promises ==========
let requestId;
const wrapper = async (
id: string
): Promise<SuccessNodePromises<any> | RejectedNodePromises> => {
Expand Down Expand Up @@ -2039,10 +2038,11 @@ export class LitNodeClientNodeJs
},
this.config.retryTolerance
);
const requestId = res.requestId;

// -- case: promises rejected
if (res.success === false) {
this._throwNodeError(res as RejectedNodePromises);
this._throwNodeError(res as RejectedNodePromises, requestId);
}

const signatureShares: Array<NodeBlsSigningShare> = (
Expand Down Expand Up @@ -2236,7 +2236,6 @@ export class LitNodeClientNodeJs

log('identityParam', identityParam);

let requestId;
// ========== Get Network Signature ==========
const wrapper = async (
id: string
Expand Down Expand Up @@ -2280,11 +2279,11 @@ export class LitNodeClientNodeJs
this.config.retryTolerance
);

requestId = res.requestId;
const requestId = res.requestId;

// -- case: promises rejected
if (res.success === false) {
this._throwNodeError(res as RejectedNodePromises);
this._throwNodeError(res as RejectedNodePromises, requestId);
}

const signatureShares: Array<NodeBlsSigningShare> = (
Expand Down Expand Up @@ -2621,7 +2620,7 @@ export class LitNodeClientNodeJs

// -- case: promises rejected
if (!this.#isSuccessNodePromises(res)) {
this._throwNodeError(res as RejectedNodePromises);
this._throwNodeError(res as RejectedNodePromises, requestId);
return {} as SignSessionKeyResponse;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/lit-node-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
},
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/misc-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/misc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
"version": "3.2.1",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
24 changes: 6 additions & 18 deletions packages/misc/src/lib/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
KV,
NodeClientErrorV0,
NodeClientErrorV1,
NodeErrorV0,
NodeErrorV1,
NodeErrorV3,
ClaimRequest,
Expand Down Expand Up @@ -130,28 +129,32 @@ export const throwErrorV1 = ({
status,
message,
errorCode,
requestId,
}: NodeClientErrorV1): never => {
const errConstructorFunc = function (
this: any,
errorKind: string,
status: number,
details: string[],
message?: string,
errorCode?: string
errorCode?: string,
requestId?: string
) {
this.message = message;
this.errorCode = errorCode;
this.errorKind = errorKind;
this.status = status;
this.details = details;
this.requestId = requestId;
};

throw new (errConstructorFunc as any)(
errorKind,
status,
details,
message,
errorCode
errorCode,
requestId
);
};

Expand Down Expand Up @@ -180,21 +183,6 @@ export const isNodeClientErrorV0 = (
return nodeError.hasOwnProperty('errorCode');
};

export const isNodeErrorV1 = (
nodeError: NodeErrorV0 | NodeErrorV1
): nodeError is NodeErrorV1 => {
return (
nodeError.hasOwnProperty('errorCode') &&
nodeError.hasOwnProperty('errorKind')
);
};

export const isNodeErrorV0 = (
nodeError: NodeErrorV0 | NodeErrorV1
): nodeError is NodeErrorV0 => {
return nodeError.hasOwnProperty('errorCode');
};

declare global {
var litConfig: any;
var wasmExport: any;
Expand Down
Loading