@requestnetwork/utils 0.36.1-next.1862 → 0.36.1-next.1864
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/crypto/crypto-wrapper.js +6 -6
- package/dist/crypto/ec-utils.js +2 -2
- package/dist/crypto.js +2 -2
- package/dist/encryption.js +2 -2
- package/dist/estimate-gas-fees.js +1 -1
- package/dist/providers.d.ts +10 -6
- package/dist/providers.d.ts.map +1 -1
- package/dist/providers.js +1 -1
- package/dist/retry.d.ts +1 -1
- package/dist/retry.js +2 -2
- package/package.json +6 -6
|
@@ -16,7 +16,7 @@ const AUTH_TAG_LENGTH = 16;
|
|
|
16
16
|
* @returns Promise resolving the 32 bytes generated
|
|
17
17
|
*/
|
|
18
18
|
function random32Bytes() {
|
|
19
|
-
return
|
|
19
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
// eslint-disable-next-line no-magic-numbers
|
|
21
21
|
return randomBytes(32);
|
|
22
22
|
});
|
|
@@ -31,7 +31,7 @@ exports.random32Bytes = random32Bytes;
|
|
|
31
31
|
* @returns Promise resolving a buffer containing the IV and the encrypted data
|
|
32
32
|
*/
|
|
33
33
|
function encryptWithAes256cbc(data, key) {
|
|
34
|
-
return
|
|
34
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
// Generate randomly the Initialization Vector
|
|
36
36
|
const iv = yield randomBytes(INITIALIZATION_VECTOR_LENGTH);
|
|
37
37
|
// Create the cipher object to encrypt data
|
|
@@ -52,7 +52,7 @@ exports.encryptWithAes256cbc = encryptWithAes256cbc;
|
|
|
52
52
|
* @returns Promise resolving a buffer containing the IV and the encrypted data
|
|
53
53
|
*/
|
|
54
54
|
function encryptWithAes256gcm(data, key) {
|
|
55
|
-
return
|
|
55
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
56
56
|
// Generate randomly the Initialization Vector
|
|
57
57
|
const iv = yield randomBytes(INITIALIZATION_VECTOR_LENGTH);
|
|
58
58
|
// Create the cipher object to encrypt data
|
|
@@ -74,7 +74,7 @@ exports.encryptWithAes256gcm = encryptWithAes256gcm;
|
|
|
74
74
|
* @returns Promise resolving a buffer containing the data decrypted
|
|
75
75
|
*/
|
|
76
76
|
function decryptWithAes256cbc(encryptedAndIv, key) {
|
|
77
|
-
return
|
|
77
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
78
78
|
// Get the IV
|
|
79
79
|
const iv = encryptedAndIv.slice(0, INITIALIZATION_VECTOR_LENGTH);
|
|
80
80
|
// Get the encrypted data itself
|
|
@@ -96,7 +96,7 @@ exports.decryptWithAes256cbc = decryptWithAes256cbc;
|
|
|
96
96
|
* @returns Promise resolving a buffer containing the data decrypted
|
|
97
97
|
*/
|
|
98
98
|
function decryptWithAes256gcm(encryptedAndIv, key) {
|
|
99
|
-
return
|
|
99
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
100
100
|
// Get the IV
|
|
101
101
|
const iv = encryptedAndIv.slice(0, INITIALIZATION_VECTOR_LENGTH);
|
|
102
102
|
// Get the Auth tag
|
|
@@ -119,7 +119,7 @@ exports.decryptWithAes256gcm = decryptWithAes256gcm;
|
|
|
119
119
|
* @returns Promise resolving the N bytes generated
|
|
120
120
|
*/
|
|
121
121
|
function randomBytes(n) {
|
|
122
|
-
return
|
|
122
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
123
123
|
return new Promise((resolve, reject) => {
|
|
124
124
|
(0, crypto_1.randomBytes)(n, (error, buffer) => {
|
|
125
125
|
if (error) {
|
package/dist/crypto/ec-utils.js
CHANGED
|
@@ -109,7 +109,7 @@ exports.ecRecover = ecRecover;
|
|
|
109
109
|
* @returns the encrypted data
|
|
110
110
|
*/
|
|
111
111
|
function ecEncrypt(publicKey, data) {
|
|
112
|
-
return
|
|
112
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
113
113
|
try {
|
|
114
114
|
// encrypts the data with the publicKey, returns the encrypted data with encryption parameters (such as IV..)
|
|
115
115
|
const compressed = compressPublicKey(publicKey);
|
|
@@ -141,7 +141,7 @@ exports.ecEncrypt = ecEncrypt;
|
|
|
141
141
|
* @returns the decrypted data
|
|
142
142
|
*/
|
|
143
143
|
function ecDecrypt(privateKey, data) {
|
|
144
|
-
return
|
|
144
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
145
145
|
try {
|
|
146
146
|
const buf = yield EcCrypto.decrypt(Buffer.from(privateKey.replace(/^0x/, ''), 'hex'), eciesSplit(data));
|
|
147
147
|
return buf.toString();
|
package/dist/crypto.js
CHANGED
|
@@ -79,7 +79,7 @@ exports.last20bytesOfNormalizedKeccak256Hash = last20bytesOfNormalizedKeccak256H
|
|
|
79
79
|
* @returns a random buffer of 32 bytes in a base64 string
|
|
80
80
|
*/
|
|
81
81
|
function generate32BufferKey() {
|
|
82
|
-
return
|
|
82
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
83
83
|
return (yield (0, crypto_wrapper_1.random32Bytes)()).toString('base64');
|
|
84
84
|
});
|
|
85
85
|
}
|
|
@@ -92,7 +92,7 @@ exports.generate32BufferKey = generate32BufferKey;
|
|
|
92
92
|
* @returns a string of 8 random bytes
|
|
93
93
|
*/
|
|
94
94
|
function generate8randomBytes() {
|
|
95
|
-
return
|
|
95
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
96
96
|
const random32BytesHex = yield (0, crypto_wrapper_1.random32Bytes)();
|
|
97
97
|
return random32BytesHex.slice(0, 8).toString('hex');
|
|
98
98
|
});
|
package/dist/encryption.js
CHANGED
|
@@ -29,7 +29,7 @@ exports.getIdentityFromEncryptionParams = getIdentityFromEncryptionParams;
|
|
|
29
29
|
* @returns the encrypted data
|
|
30
30
|
*/
|
|
31
31
|
function encrypt(data, encryptionParams) {
|
|
32
|
-
return
|
|
32
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
33
33
|
if (encryptionParams.method === types_1.EncryptionTypes.METHOD.ECIES) {
|
|
34
34
|
const encryptedData = yield (0, index_1.ecEncrypt)(encryptionParams.key, data);
|
|
35
35
|
return {
|
|
@@ -65,7 +65,7 @@ exports.encrypt = encrypt;
|
|
|
65
65
|
* @returns the decrypted data
|
|
66
66
|
*/
|
|
67
67
|
function decrypt(encryptedData, decryptionParams) {
|
|
68
|
-
return
|
|
68
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
69
69
|
if (encryptedData.type === types_1.EncryptionTypes.METHOD.ECIES) {
|
|
70
70
|
if (decryptionParams.method !== types_1.EncryptionTypes.METHOD.ECIES) {
|
|
71
71
|
throw new Error(`decryptionParams.method should be ${types_1.EncryptionTypes.METHOD.ECIES}`);
|
|
@@ -17,7 +17,7 @@ const index_1 = require("./index");
|
|
|
17
17
|
* - gasPrice: Optional fallback: the gas price for this transaction.
|
|
18
18
|
*/
|
|
19
19
|
function estimateGasFees({ provider, gasPriceMin, }) {
|
|
20
|
-
return
|
|
20
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
const suggestedFee = yield (0, eip1559_fee_suggestions_ethers_1.suggestFees)(provider);
|
|
22
22
|
const baseFee = (0, index_1.maxBigNumber)(suggestedFee.baseFeeSuggestion, gasPriceMin || ethers_1.constants.Zero);
|
|
23
23
|
const maxPriorityFeePerGas = (0, index_1.maxBigNumber)(suggestedFee.maxPriorityFeeSuggestions.urgent, gasPriceMin || ethers_1.constants.Zero);
|
package/dist/providers.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { LogTypes } from '@requestnetwork/types';
|
|
2
2
|
import { providers } from 'ethers';
|
|
3
|
-
|
|
3
|
+
type ProviderFactory = (network: string | undefined) => providers.Provider | string;
|
|
4
4
|
/**
|
|
5
5
|
* @param network the network to connect to
|
|
6
6
|
* @param defaultFactory the defaultFactory to use as fallback if needed
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
type CurrentProviderFactory = (network: string | undefined, defaultFactory: ProviderFactory) => providers.Provider | string;
|
|
9
|
+
/**
|
|
10
|
+
* Default API_KEYS configuration, can be overriden using initPaymentDetectionApiKeys
|
|
11
|
+
*/
|
|
12
|
+
declare let providersApiKeys: Record<string, string | (() => string)>;
|
|
9
13
|
/**
|
|
10
14
|
* @param defaultProviderOptions Default Provider Options as specified in https://docs.ethers.io/v5/api/providers/#providers-getDefaultProvider */
|
|
11
|
-
declare const initPaymentDetectionApiKeys: (defaultProviderOptions?:
|
|
15
|
+
declare const initPaymentDetectionApiKeys: (defaultProviderOptions?: typeof providersApiKeys) => void;
|
|
12
16
|
/**
|
|
13
17
|
* Define default URLs for networks supported by Request payment detection but not by ethers' Infura Provider
|
|
14
18
|
*/
|
|
@@ -17,7 +21,7 @@ declare const networkRpcs: Record<string, string>;
|
|
|
17
21
|
* Override the default providerFactory, which relies mainly on Infura.
|
|
18
22
|
* @param providerFactory if not specify, will reset to the default factory
|
|
19
23
|
*/
|
|
20
|
-
declare const setProviderFactory: (providerFactory?: CurrentProviderFactory
|
|
24
|
+
declare const setProviderFactory: (providerFactory?: CurrentProviderFactory) => void;
|
|
21
25
|
/**
|
|
22
26
|
* Returns a Web3 Provider for the given `network`.
|
|
23
27
|
*
|
|
@@ -29,8 +33,8 @@ declare const setProviderFactory: (providerFactory?: CurrentProviderFactory | un
|
|
|
29
33
|
*
|
|
30
34
|
* @param network the blockchain network. See https://chainid.network/chains.json `network` field for reference
|
|
31
35
|
*/
|
|
32
|
-
declare const getDefaultProvider: (network?: string
|
|
36
|
+
declare const getDefaultProvider: (network?: string) => providers.Provider;
|
|
33
37
|
declare const getCeloProvider: () => providers.Provider;
|
|
34
|
-
declare const isEip1559Supported: (provider: providers.Provider | providers.JsonRpcProvider, logger?: LogTypes.ILogger
|
|
38
|
+
declare const isEip1559Supported: (provider: providers.Provider | providers.JsonRpcProvider, logger?: LogTypes.ILogger) => Promise<boolean>;
|
|
35
39
|
export { setProviderFactory, initPaymentDetectionApiKeys, isEip1559Supported, getDefaultProvider, getCeloProvider, networkRpcs, };
|
|
36
40
|
//# sourceMappingURL=providers.d.ts.map
|
package/dist/providers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAa,MAAM,QAAQ,CAAC;AAE9C,
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAa,MAAM,QAAQ,CAAC;AAE9C,KAAK,eAAe,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,KAAK,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;AAGpF;;;GAGG;AACH,KAAK,sBAAsB,GAAG,CAC5B,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,cAAc,EAAE,eAAe,KAC5B,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;AAEjC;;GAEG;AACH,QAAA,IAAI,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAG3D,CAAC;AAEF;mJACmJ;AACnJ,QAAA,MAAM,2BAA2B,4BAA6B,uBAAuB,KAAG,IAEvF,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAevC,CAAC;AA6DF;;;GAGG;AACH,QAAA,MAAM,kBAAkB,qBAAsB,sBAAsB,KAAG,IAEtE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,QAAA,MAAM,kBAAkB,aAAc,MAAM,KAAG,UAAU,QAMxD,CAAC;AAEF,QAAA,MAAM,eAAe,QAAO,UAAU,QAarC,CAAC;AAEF,QAAA,MAAM,kBAAkB,aACZ,UAAU,QAAQ,GAAG,UAAU,eAAe,WAC/C,SAAS,OAAO,KACxB,QAAQ,OAAO,CAWjB,CAAC;AAEF,OAAO,EACL,kBAAkB,EAClB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,WAAW,GACZ,CAAC"}
|
package/dist/providers.js
CHANGED
|
@@ -123,7 +123,7 @@ const getCeloProvider = () => {
|
|
|
123
123
|
return provider;
|
|
124
124
|
};
|
|
125
125
|
exports.getCeloProvider = getCeloProvider;
|
|
126
|
-
const isEip1559Supported = (provider, logger) =>
|
|
126
|
+
const isEip1559Supported = (provider, logger) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
127
127
|
try {
|
|
128
128
|
yield provider.send('eth_feeHistory', [1, 'latest', []]);
|
|
129
129
|
return true;
|
package/dist/retry.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @param [options.retryDelay=DEFAULT_RETRY_DELAY] The delay between retries
|
|
9
9
|
*/
|
|
10
10
|
declare const retry: <TParams extends unknown[], TReturn>(target: (...params: TParams) => TReturn | Promise<TReturn>, { context, maxRetries, retryDelay, }?: {
|
|
11
|
-
context?:
|
|
11
|
+
context?: unknown;
|
|
12
12
|
maxRetries?: number | undefined;
|
|
13
13
|
retryDelay?: number | undefined;
|
|
14
14
|
}) => (...params: TParams) => Promise<TReturn>;
|
package/dist/retry.js
CHANGED
|
@@ -21,12 +21,12 @@ const retry = (target, { context, maxRetries = DEFAULT_MAX_RETRIES, retryDelay =
|
|
|
21
21
|
target = target.bind(context);
|
|
22
22
|
}
|
|
23
23
|
// Returns an external function that will contain the retry counter
|
|
24
|
-
return (...args) =>
|
|
24
|
+
return (...args) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
25
25
|
// The current amount of retries
|
|
26
26
|
let retry = 0;
|
|
27
27
|
// Returns the retrying function that can be called
|
|
28
28
|
return (function retryFunction(...innerArgs) {
|
|
29
|
-
return
|
|
29
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
30
30
|
try {
|
|
31
31
|
// Call the target function with the target object as context
|
|
32
32
|
return yield target(...innerArgs);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@requestnetwork/utils",
|
|
3
|
-
"version": "0.36.1-next.
|
|
3
|
+
"version": "0.36.1-next.1864+cfea8a31",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"test:watch": "yarn test --watch"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@requestnetwork/types": "0.36.1-next.
|
|
43
|
+
"@requestnetwork/types": "0.36.1-next.1864+cfea8a31",
|
|
44
44
|
"eccrypto": "1.1.6",
|
|
45
45
|
"eip1559-fee-suggestions-ethers": "1.3.3",
|
|
46
46
|
"ethers": "5.5.1",
|
|
47
47
|
"secp256k1": "4.0.2",
|
|
48
|
-
"tslib": "2.
|
|
48
|
+
"tslib": "2.5.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/eccrypto": "1.1.2",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"shx": "0.3.2",
|
|
55
55
|
"source-map-support": "0.5.19",
|
|
56
56
|
"ts-jest": "26.3.0",
|
|
57
|
-
"ts-node": "9.
|
|
58
|
-
"typescript": "4.
|
|
57
|
+
"ts-node": "10.9.1",
|
|
58
|
+
"typescript": "4.9.5"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "cfea8a31e39ba4315b8ffc9971cbb3155be2dde1"
|
|
61
61
|
}
|