Skip to content

Conversation

@WorldThirteen
Copy link
Collaborator

There was a problem with the sync-request library, it contains bugs and is no longer actively maintained.
The most critical bug for tl_creaate use-case was hanging connection and useless timeout param which leads tl-create to hang forever if some server isn't responding.
To make network requests more reliable I used node-fetch instead of sync-request which forces me to refactor sync flow into async/await style.
The user agent string was slightly modified since I had a guess (just guess based on some experiments) that some remote servers might rate limiting/filtering by user-agent, so I pick not so common (random one doesn't give a positive effect).

There were also some tradeoffs in the code I used to make (probably temporary, will be commented in this PR near the code itself.)

@microshine, @rmhrisk, please review.

(global as any)["DOMParser"] = DOMParser;
(global as any)["XMLSerializer"] = XMLSerializer;
XAdES.Application.setEngine("@peculiar/webcrypto", crypto);
XAdES.Application.setEngine("@peculiar/webcrypto", crypto as Crypto);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required since it seems Webcrypto's Crypto interface is slightly different from native Crypto in some stage detail:

src/formats/eutl.ts:8:52 - error TS2345: Argument of type 'import("/Users/worldthirteen/Documents/Projects/pv/tl-create/node_modules/@peculiar/webcrypto/index").Crypto' is not assignable to parameter of type 'Crypto'.
  Types of property 'getRandomValues' are incompatible.
    Type '<T extends Uint8Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | null>(array: T) => T' is not assignable to type '<T extends ArrayBufferView | null>(array: T) => T'.
      Types of parameters 'array' and 'array' are incompatible.
        Type 'T' is not assignable to type 'Uint8Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | null'.
          Type 'ArrayBufferView | null' is not assignable to type 'Uint8Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | null'.
            Type 'ArrayBufferView' is not assignable to type 'Uint8Array | Int8Array | Int16Array | Int32Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | null'.
              Type 'ArrayBufferView' is missing the following properties from type 'DataView': getFloat32, getFloat64, getInt8, getInt16, and 17 more.
                Type 'T' is not assignable to type 'DataView'.
                  Type 'ArrayBufferView | null' is not assignable to type 'DataView'.
                    Type 'null' is not assignable to type 'DataView'.

8 XAdES.Application.setEngine("@peculiar/webcrypto", crypto);

so I was forced to add this as.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that TS changes WebCrypto interfaces from version to version. We need to upgrade TS package version for all of our crypto modules

"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
"skipLibCheck": true,
"useUnknownInCatchVariables": false,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the code contains catch and the error type doesn't correctly validate, I was forced to disable this check.

@WorldThirteen WorldThirteen requested a review from rmhrisk October 6, 2021 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants