@requestnetwork/utils 0.28.0 → 0.28.1-next.709
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/README.md +2 -20
- package/dist/amount.d.ts +5 -9
- package/dist/amount.d.ts.map +1 -1
- package/dist/amount.js +19 -23
- package/dist/amount.js.map +1 -1
- package/dist/bignumber.d.ts +7 -0
- package/dist/bignumber.d.ts.map +1 -0
- package/dist/bignumber.js +11 -0
- package/dist/bignumber.js.map +1 -0
- package/dist/cached-throttle.d.ts +2 -2
- package/dist/cached-throttle.d.ts.map +1 -1
- package/dist/cached-throttle.js +5 -3
- package/dist/cached-throttle.js.map +1 -1
- package/dist/crypto/crypto-wrapper.d.ts +1 -8
- package/dist/crypto/crypto-wrapper.d.ts.map +1 -1
- package/dist/crypto/crypto-wrapper.js +19 -31
- package/dist/crypto/crypto-wrapper.js.map +1 -1
- package/dist/crypto/ec-utils.d.ts +6 -14
- package/dist/crypto/ec-utils.d.ts.map +1 -1
- package/dist/crypto/ec-utils.js +77 -41
- package/dist/crypto/ec-utils.js.map +1 -1
- package/dist/crypto.d.ts +14 -26
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +40 -30
- package/dist/crypto.js.map +1 -1
- package/dist/encryption.d.ts +1 -6
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +15 -27
- package/dist/encryption.js.map +1 -1
- package/dist/identity.d.ts +4 -9
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +11 -12
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +12 -69
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +66 -28
- package/dist/index.js.map +1 -1
- package/dist/normalize-gas-fees.d.ts +19 -0
- package/dist/normalize-gas-fees.d.ts.map +1 -0
- package/dist/normalize-gas-fees.js +44 -0
- package/dist/normalize-gas-fees.js.map +1 -0
- package/dist/providers.d.ts +40 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +149 -0
- package/dist/providers.js.map +1 -0
- package/dist/retry.d.ts +10 -6
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +15 -16
- package/dist/retry.js.map +1 -1
- package/dist/signature.d.ts +3 -8
- package/dist/signature.d.ts.map +1 -1
- package/dist/signature.js +13 -19
- package/dist/signature.js.map +1 -1
- package/dist/simple-logger.d.ts +1 -1
- package/dist/simple-logger.d.ts.map +1 -1
- package/dist/simple-logger.js +4 -3
- package/dist/simple-logger.js.map +1 -1
- package/dist/utils.d.ts +11 -20
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +20 -21
- package/dist/utils.js.map +1 -1
- package/package.json +18 -26
- package/CHANGELOG.md +0 -1047
package/dist/identity.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.supportedIdentities = exports.normalizeIdentityValue = exports.identityHasError = exports.areEqualIdentities = void 0;
|
|
3
4
|
const types_1 = require("@requestnetwork/types");
|
|
4
5
|
const supportedIdentities = [
|
|
5
6
|
types_1.IdentityTypes.TYPE.ETHEREUM_ADDRESS,
|
|
6
7
|
types_1.IdentityTypes.TYPE.ETHEREUM_SMART_CONTRACT,
|
|
7
8
|
];
|
|
8
|
-
|
|
9
|
-
* Module to manage Request Logic Identity
|
|
10
|
-
*/
|
|
11
|
-
exports.default = {
|
|
12
|
-
areEqual,
|
|
13
|
-
hasError,
|
|
14
|
-
normalizeIdentityValue,
|
|
15
|
-
supportedIdentities,
|
|
16
|
-
};
|
|
9
|
+
exports.supportedIdentities = supportedIdentities;
|
|
17
10
|
/**
|
|
18
11
|
* Checks if two identities are equals
|
|
19
12
|
*
|
|
@@ -21,9 +14,13 @@ exports.default = {
|
|
|
21
14
|
* @param IIdentity id2 second identity
|
|
22
15
|
* @returns boolean
|
|
23
16
|
*/
|
|
24
|
-
function
|
|
25
|
-
return (id1
|
|
17
|
+
function areEqualIdentities(id1, id2) {
|
|
18
|
+
return (!!id1 &&
|
|
19
|
+
!!id2 &&
|
|
20
|
+
id1.type === id2.type &&
|
|
21
|
+
normalizeIdentityValue(id1.value) === normalizeIdentityValue(id2.value));
|
|
26
22
|
}
|
|
23
|
+
exports.areEqualIdentities = areEqualIdentities;
|
|
27
24
|
/**
|
|
28
25
|
* Normalizes identity values
|
|
29
26
|
*
|
|
@@ -33,13 +30,14 @@ function areEqual(id1, id2) {
|
|
|
33
30
|
function normalizeIdentityValue(value) {
|
|
34
31
|
return value.toLowerCase();
|
|
35
32
|
}
|
|
33
|
+
exports.normalizeIdentityValue = normalizeIdentityValue;
|
|
36
34
|
/**
|
|
37
35
|
* Checks if the identity has an error
|
|
38
36
|
*
|
|
39
37
|
* @param id identity to check
|
|
40
38
|
* @returns the error or null if valid
|
|
41
39
|
*/
|
|
42
|
-
function
|
|
40
|
+
function identityHasError(id) {
|
|
43
41
|
if (!supportedIdentities.includes(id.type)) {
|
|
44
42
|
return 'identity type not supported';
|
|
45
43
|
}
|
|
@@ -48,4 +46,5 @@ function hasError(id) {
|
|
|
48
46
|
}
|
|
49
47
|
return null;
|
|
50
48
|
}
|
|
49
|
+
exports.identityHasError = identityHasError;
|
|
51
50
|
//# sourceMappingURL=identity.js.map
|
package/dist/identity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":";;;AAAA,iDAAsD;AAEtD,MAAM,mBAAmB,GAAyB;IAChD,qBAAa,CAAC,IAAI,CAAC,gBAAgB;IACnC,qBAAa,CAAC,IAAI,CAAC,uBAAuB;CAC3C,CAAC;AAKqE,kDAAmB;AAE1F;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,GAA6B,EAAE,GAA6B;IACtF,OAAO,CACL,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,GAAG;QACL,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI;QACrB,sBAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,sBAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,CACxE,CAAC;AACJ,CAAC;AAhBQ,gDAAkB;AAkB3B;;;;;GAKG;AACH,SAAS,sBAAsB,CAAC,KAAa;IAC3C,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;AAC7B,CAAC;AA1B8C,wDAAsB;AA4BrE;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,EAA2B;IACnD,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;QAC1C,OAAO,6BAA6B,CAAC;KACtC;IACD,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,qBAAqB,CAAC,KAAK,IAAI,EAAE;QAClD,OAAO,4CAA4C,CAAC;KACrD;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AA1C4B,4CAAgB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,73 +1,16 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import SimpleLogger from './simple-logger';
|
|
3
|
-
declare const _default: {
|
|
4
|
-
SimpleLogger: typeof SimpleLogger;
|
|
5
|
-
amount: {
|
|
6
|
-
add: (amount: import("@requestnetwork/types/dist/request-logic-types").Amount, delta: import("@requestnetwork/types/dist/request-logic-types").Amount) => string;
|
|
7
|
-
isValid: (amount: import("@requestnetwork/types/dist/request-logic-types").Amount) => boolean;
|
|
8
|
-
reduce: (amount: import("@requestnetwork/types/dist/request-logic-types").Amount, delta: import("@requestnetwork/types/dist/request-logic-types").Amount) => string;
|
|
9
|
-
};
|
|
10
|
-
cachedThrottle: (target: any, minimumDelay: number) => any;
|
|
11
|
-
crypto: {
|
|
12
|
-
CryptoWrapper: {
|
|
13
|
-
decryptWithAes256cbc: (encryptedAndIv: Buffer, key: Buffer) => Promise<Buffer>;
|
|
14
|
-
decryptWithAes256gcm: (encryptedAndIv: Buffer, key: Buffer) => Promise<Buffer>;
|
|
15
|
-
encryptWithAes256cbc: (data: Buffer, key: Buffer) => Promise<Buffer>;
|
|
16
|
-
encryptWithAes256gcm: (data: Buffer, key: Buffer) => Promise<Buffer>;
|
|
17
|
-
random32Bytes: () => Promise<Buffer>;
|
|
18
|
-
};
|
|
19
|
-
EcUtils: {
|
|
20
|
-
decrypt: (privateKey: string, encrypted: string) => Promise<string>;
|
|
21
|
-
encrypt: (publicKey: string, data: string) => Promise<string>;
|
|
22
|
-
getAddressFromPrivateKey: (privateKey: string) => string;
|
|
23
|
-
getAddressFromPublicKey: (publicKey: string) => string;
|
|
24
|
-
recover: (signature: string, data: string) => string;
|
|
25
|
-
sign: (privateKey: string, data: string) => string;
|
|
26
|
-
};
|
|
27
|
-
generate32BufferKey: () => Promise<string>;
|
|
28
|
-
generate8randomBytes: () => Promise<string>;
|
|
29
|
-
keccak256Hash: (data: string) => string;
|
|
30
|
-
normalize: (data: any) => string;
|
|
31
|
-
normalizeKeccak256Hash: (data: any) => import("@requestnetwork/types/dist/multi-format/hash-types").IHash;
|
|
32
|
-
};
|
|
33
|
-
deepCopy: (variable: any) => any;
|
|
34
|
-
deepSort: (nestedObject: any) => any;
|
|
35
|
-
encryption: {
|
|
36
|
-
decrypt: (encryptedData: import("@requestnetwork/types/dist/encryption-types").IEncryptedData, decryptionParams: import("@requestnetwork/types/dist/encryption-types").IDecryptionParameters) => Promise<string>;
|
|
37
|
-
encrypt: (data: string, encryptionParams: import("@requestnetwork/types/dist/encryption-types").IEncryptionParameters) => Promise<import("@requestnetwork/types/dist/encryption-types").IEncryptedData>;
|
|
38
|
-
getIdentityFromEncryptionParams: (encryptionParams: import("@requestnetwork/types/dist/encryption-types").IEncryptionParameters) => import("@requestnetwork/types/dist/identity-types").IIdentity;
|
|
39
|
-
};
|
|
40
|
-
flatten2DimensionsArray: (twoDimensionsArray: any[]) => any[];
|
|
41
|
-
getCurrentTimestampInSecond: () => number;
|
|
42
|
-
identity: {
|
|
43
|
-
areEqual: (id1: import("@requestnetwork/types/dist/identity-types").IIdentity, id2: import("@requestnetwork/types/dist/identity-types").IIdentity) => boolean;
|
|
44
|
-
hasError: (id: import("@requestnetwork/types/dist/identity-types").IIdentity) => string | null;
|
|
45
|
-
normalizeIdentityValue: (value: string) => string;
|
|
46
|
-
supportedIdentities: import("@requestnetwork/types/dist/identity-types").TYPE[];
|
|
47
|
-
};
|
|
48
|
-
isString: (variable: any) => boolean;
|
|
49
|
-
retry: (target: any, { context, maxRetries, retryDelay, }?: {
|
|
50
|
-
context?: any;
|
|
51
|
-
maxRetries?: number | undefined;
|
|
52
|
-
retryDelay?: number | undefined;
|
|
53
|
-
}) => any;
|
|
54
|
-
signature: {
|
|
55
|
-
getIdentityFromSignatureParams: (signatureParams: import("@requestnetwork/types/dist/signature-types").ISignatureParameters) => import("@requestnetwork/types/dist/identity-types").IIdentity;
|
|
56
|
-
recover: (signedData: import("@requestnetwork/types/dist/signature-types").ISignedData) => import("@requestnetwork/types/dist/identity-types").IIdentity;
|
|
57
|
-
sign: (data: any, signatureParams: import("@requestnetwork/types/dist/signature-types").ISignatureParameters) => import("@requestnetwork/types/dist/signature-types").ISignedData;
|
|
58
|
-
};
|
|
59
|
-
timeoutPromise: (timeout: number, message: string) => Promise<any>;
|
|
60
|
-
unique: (array: any[]) => {
|
|
61
|
-
uniqueItems: any[];
|
|
62
|
-
duplicates: any[];
|
|
63
|
-
};
|
|
64
|
-
uniqueByProperty: (array: any[], property: string) => {
|
|
65
|
-
uniqueItems: any[];
|
|
66
|
-
duplicates: any[];
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
1
|
/**
|
|
70
2
|
* Collection of general purpose utility function
|
|
71
3
|
*/
|
|
72
|
-
export
|
|
4
|
+
export { addAmount, isValidAmount, reduceAmount } from './amount';
|
|
5
|
+
export { minBigNumber, maxBigNumber } from './bignumber';
|
|
6
|
+
export { cachedThrottle } from './cached-throttle';
|
|
7
|
+
export { decryptWithAes256cbc, decryptWithAes256gcm, encryptWithAes256cbc, encryptWithAes256gcm, random32Bytes, ecDecrypt, ecEncrypt, getAddressFromPrivateKey, getAddressFromPublicKey, ecRecover, ecSign, generate32BufferKey, generate8randomBytes, keccak256Hash, last20bytesOfNormalizedKeccak256Hash, normalize, normalizeKeccak256Hash, } from './crypto';
|
|
8
|
+
export { decrypt, encrypt, getIdentityFromEncryptionParams } from './encryption';
|
|
9
|
+
export { normalizeGasFees } from './normalize-gas-fees';
|
|
10
|
+
export { areEqualIdentities, identityHasError, normalizeIdentityValue, supportedIdentities, } from './identity';
|
|
11
|
+
export { setProviderFactory, initPaymentDetectionApiKeys, isEip1559Supported, getDefaultProvider, getCeloProvider, networkRpcs, } from './providers';
|
|
12
|
+
export { retry } from './retry';
|
|
13
|
+
export { getIdentityFromSignatureParams, recoverSigner, sign } from './signature';
|
|
14
|
+
export { SimpleLogger } from './simple-logger';
|
|
15
|
+
export { deepCopy, deepSort, flatten2DimensionsArray, getCurrentTimestampInSecond, isString, timeoutPromise, unique, uniqueByProperty, notNull, } from './utils';
|
|
73
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,SAAS,EACT,SAAS,EACT,wBAAwB,EACxB,uBAAuB,EACvB,SAAS,EACT,MAAM,EACN,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,oCAAoC,EACpC,SAAS,EACT,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,kBAAkB,EAClB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,8BAA8B,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAElF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,uBAAuB,EACvB,2BAA2B,EAC3B,QAAQ,EACR,cAAc,EACd,MAAM,EACN,gBAAgB,EAChB,OAAO,GACR,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const amount_1 = require("./amount");
|
|
4
|
-
const cached_throttle_1 = require("./cached-throttle");
|
|
5
|
-
const crypto_1 = require("./crypto");
|
|
6
|
-
const encryption_1 = require("./encryption");
|
|
7
|
-
const identity_1 = require("./identity");
|
|
8
|
-
const retry_1 = require("./retry");
|
|
9
|
-
const signature_1 = require("./signature");
|
|
10
|
-
const simple_logger_1 = require("./simple-logger");
|
|
11
|
-
const utils_1 = require("./utils");
|
|
12
2
|
/**
|
|
13
3
|
* Collection of general purpose utility function
|
|
14
4
|
*/
|
|
15
|
-
exports
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.uniqueByProperty = exports.unique = exports.timeoutPromise = exports.isString = exports.getCurrentTimestampInSecond = exports.flatten2DimensionsArray = exports.deepSort = exports.deepCopy = exports.SimpleLogger = exports.sign = exports.recoverSigner = exports.getIdentityFromSignatureParams = exports.retry = exports.networkRpcs = exports.getCeloProvider = exports.getDefaultProvider = exports.isEip1559Supported = exports.initPaymentDetectionApiKeys = exports.setProviderFactory = exports.supportedIdentities = exports.normalizeIdentityValue = exports.identityHasError = exports.areEqualIdentities = exports.normalizeGasFees = exports.getIdentityFromEncryptionParams = exports.encrypt = exports.decrypt = exports.normalizeKeccak256Hash = exports.normalize = exports.last20bytesOfNormalizedKeccak256Hash = exports.keccak256Hash = exports.generate8randomBytes = exports.generate32BufferKey = exports.ecSign = exports.ecRecover = exports.getAddressFromPublicKey = exports.getAddressFromPrivateKey = exports.ecEncrypt = exports.ecDecrypt = exports.random32Bytes = exports.encryptWithAes256gcm = exports.encryptWithAes256cbc = exports.decryptWithAes256gcm = exports.decryptWithAes256cbc = exports.cachedThrottle = exports.maxBigNumber = exports.minBigNumber = exports.reduceAmount = exports.isValidAmount = exports.addAmount = void 0;
|
|
7
|
+
exports.notNull = void 0;
|
|
8
|
+
var amount_1 = require("./amount");
|
|
9
|
+
Object.defineProperty(exports, "addAmount", { enumerable: true, get: function () { return amount_1.addAmount; } });
|
|
10
|
+
Object.defineProperty(exports, "isValidAmount", { enumerable: true, get: function () { return amount_1.isValidAmount; } });
|
|
11
|
+
Object.defineProperty(exports, "reduceAmount", { enumerable: true, get: function () { return amount_1.reduceAmount; } });
|
|
12
|
+
var bignumber_1 = require("./bignumber");
|
|
13
|
+
Object.defineProperty(exports, "minBigNumber", { enumerable: true, get: function () { return bignumber_1.minBigNumber; } });
|
|
14
|
+
Object.defineProperty(exports, "maxBigNumber", { enumerable: true, get: function () { return bignumber_1.maxBigNumber; } });
|
|
15
|
+
var cached_throttle_1 = require("./cached-throttle");
|
|
16
|
+
Object.defineProperty(exports, "cachedThrottle", { enumerable: true, get: function () { return cached_throttle_1.cachedThrottle; } });
|
|
17
|
+
var crypto_1 = require("./crypto");
|
|
18
|
+
Object.defineProperty(exports, "decryptWithAes256cbc", { enumerable: true, get: function () { return crypto_1.decryptWithAes256cbc; } });
|
|
19
|
+
Object.defineProperty(exports, "decryptWithAes256gcm", { enumerable: true, get: function () { return crypto_1.decryptWithAes256gcm; } });
|
|
20
|
+
Object.defineProperty(exports, "encryptWithAes256cbc", { enumerable: true, get: function () { return crypto_1.encryptWithAes256cbc; } });
|
|
21
|
+
Object.defineProperty(exports, "encryptWithAes256gcm", { enumerable: true, get: function () { return crypto_1.encryptWithAes256gcm; } });
|
|
22
|
+
Object.defineProperty(exports, "random32Bytes", { enumerable: true, get: function () { return crypto_1.random32Bytes; } });
|
|
23
|
+
Object.defineProperty(exports, "ecDecrypt", { enumerable: true, get: function () { return crypto_1.ecDecrypt; } });
|
|
24
|
+
Object.defineProperty(exports, "ecEncrypt", { enumerable: true, get: function () { return crypto_1.ecEncrypt; } });
|
|
25
|
+
Object.defineProperty(exports, "getAddressFromPrivateKey", { enumerable: true, get: function () { return crypto_1.getAddressFromPrivateKey; } });
|
|
26
|
+
Object.defineProperty(exports, "getAddressFromPublicKey", { enumerable: true, get: function () { return crypto_1.getAddressFromPublicKey; } });
|
|
27
|
+
Object.defineProperty(exports, "ecRecover", { enumerable: true, get: function () { return crypto_1.ecRecover; } });
|
|
28
|
+
Object.defineProperty(exports, "ecSign", { enumerable: true, get: function () { return crypto_1.ecSign; } });
|
|
29
|
+
Object.defineProperty(exports, "generate32BufferKey", { enumerable: true, get: function () { return crypto_1.generate32BufferKey; } });
|
|
30
|
+
Object.defineProperty(exports, "generate8randomBytes", { enumerable: true, get: function () { return crypto_1.generate8randomBytes; } });
|
|
31
|
+
Object.defineProperty(exports, "keccak256Hash", { enumerable: true, get: function () { return crypto_1.keccak256Hash; } });
|
|
32
|
+
Object.defineProperty(exports, "last20bytesOfNormalizedKeccak256Hash", { enumerable: true, get: function () { return crypto_1.last20bytesOfNormalizedKeccak256Hash; } });
|
|
33
|
+
Object.defineProperty(exports, "normalize", { enumerable: true, get: function () { return crypto_1.normalize; } });
|
|
34
|
+
Object.defineProperty(exports, "normalizeKeccak256Hash", { enumerable: true, get: function () { return crypto_1.normalizeKeccak256Hash; } });
|
|
35
|
+
var encryption_1 = require("./encryption");
|
|
36
|
+
Object.defineProperty(exports, "decrypt", { enumerable: true, get: function () { return encryption_1.decrypt; } });
|
|
37
|
+
Object.defineProperty(exports, "encrypt", { enumerable: true, get: function () { return encryption_1.encrypt; } });
|
|
38
|
+
Object.defineProperty(exports, "getIdentityFromEncryptionParams", { enumerable: true, get: function () { return encryption_1.getIdentityFromEncryptionParams; } });
|
|
39
|
+
var normalize_gas_fees_1 = require("./normalize-gas-fees");
|
|
40
|
+
Object.defineProperty(exports, "normalizeGasFees", { enumerable: true, get: function () { return normalize_gas_fees_1.normalizeGasFees; } });
|
|
41
|
+
var identity_1 = require("./identity");
|
|
42
|
+
Object.defineProperty(exports, "areEqualIdentities", { enumerable: true, get: function () { return identity_1.areEqualIdentities; } });
|
|
43
|
+
Object.defineProperty(exports, "identityHasError", { enumerable: true, get: function () { return identity_1.identityHasError; } });
|
|
44
|
+
Object.defineProperty(exports, "normalizeIdentityValue", { enumerable: true, get: function () { return identity_1.normalizeIdentityValue; } });
|
|
45
|
+
Object.defineProperty(exports, "supportedIdentities", { enumerable: true, get: function () { return identity_1.supportedIdentities; } });
|
|
46
|
+
var providers_1 = require("./providers");
|
|
47
|
+
Object.defineProperty(exports, "setProviderFactory", { enumerable: true, get: function () { return providers_1.setProviderFactory; } });
|
|
48
|
+
Object.defineProperty(exports, "initPaymentDetectionApiKeys", { enumerable: true, get: function () { return providers_1.initPaymentDetectionApiKeys; } });
|
|
49
|
+
Object.defineProperty(exports, "isEip1559Supported", { enumerable: true, get: function () { return providers_1.isEip1559Supported; } });
|
|
50
|
+
Object.defineProperty(exports, "getDefaultProvider", { enumerable: true, get: function () { return providers_1.getDefaultProvider; } });
|
|
51
|
+
Object.defineProperty(exports, "getCeloProvider", { enumerable: true, get: function () { return providers_1.getCeloProvider; } });
|
|
52
|
+
Object.defineProperty(exports, "networkRpcs", { enumerable: true, get: function () { return providers_1.networkRpcs; } });
|
|
53
|
+
var retry_1 = require("./retry");
|
|
54
|
+
Object.defineProperty(exports, "retry", { enumerable: true, get: function () { return retry_1.retry; } });
|
|
55
|
+
var signature_1 = require("./signature");
|
|
56
|
+
Object.defineProperty(exports, "getIdentityFromSignatureParams", { enumerable: true, get: function () { return signature_1.getIdentityFromSignatureParams; } });
|
|
57
|
+
Object.defineProperty(exports, "recoverSigner", { enumerable: true, get: function () { return signature_1.recoverSigner; } });
|
|
58
|
+
Object.defineProperty(exports, "sign", { enumerable: true, get: function () { return signature_1.sign; } });
|
|
59
|
+
var simple_logger_1 = require("./simple-logger");
|
|
60
|
+
Object.defineProperty(exports, "SimpleLogger", { enumerable: true, get: function () { return simple_logger_1.SimpleLogger; } });
|
|
61
|
+
var utils_1 = require("./utils");
|
|
62
|
+
Object.defineProperty(exports, "deepCopy", { enumerable: true, get: function () { return utils_1.deepCopy; } });
|
|
63
|
+
Object.defineProperty(exports, "deepSort", { enumerable: true, get: function () { return utils_1.deepSort; } });
|
|
64
|
+
Object.defineProperty(exports, "flatten2DimensionsArray", { enumerable: true, get: function () { return utils_1.flatten2DimensionsArray; } });
|
|
65
|
+
Object.defineProperty(exports, "getCurrentTimestampInSecond", { enumerable: true, get: function () { return utils_1.getCurrentTimestampInSecond; } });
|
|
66
|
+
Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return utils_1.isString; } });
|
|
67
|
+
Object.defineProperty(exports, "timeoutPromise", { enumerable: true, get: function () { return utils_1.timeoutPromise; } });
|
|
68
|
+
Object.defineProperty(exports, "unique", { enumerable: true, get: function () { return utils_1.unique; } });
|
|
69
|
+
Object.defineProperty(exports, "uniqueByProperty", { enumerable: true, get: function () { return utils_1.uniqueByProperty; } });
|
|
70
|
+
Object.defineProperty(exports, "notNull", { enumerable: true, get: function () { return utils_1.notNull; } });
|
|
33
71
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,mCAAkE;AAAzD,mGAAA,SAAS,OAAA;AAAE,uGAAA,aAAa,OAAA;AAAE,sGAAA,YAAY,OAAA;AAE/C,yCAAyD;AAAhD,yGAAA,YAAY,OAAA;AAAE,yGAAA,YAAY,OAAA;AAEnC,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AAEvB,mCAkBkB;AAjBhB,8GAAA,oBAAoB,OAAA;AACpB,8GAAA,oBAAoB,OAAA;AACpB,8GAAA,oBAAoB,OAAA;AACpB,8GAAA,oBAAoB,OAAA;AACpB,uGAAA,aAAa,OAAA;AACb,mGAAA,SAAS,OAAA;AACT,mGAAA,SAAS,OAAA;AACT,kHAAA,wBAAwB,OAAA;AACxB,iHAAA,uBAAuB,OAAA;AACvB,mGAAA,SAAS,OAAA;AACT,gGAAA,MAAM,OAAA;AACN,6GAAA,mBAAmB,OAAA;AACnB,8GAAA,oBAAoB,OAAA;AACpB,uGAAA,aAAa,OAAA;AACb,8HAAA,oCAAoC,OAAA;AACpC,mGAAA,SAAS,OAAA;AACT,gHAAA,sBAAsB,OAAA;AAGxB,2CAAiF;AAAxE,qGAAA,OAAO,OAAA;AAAE,qGAAA,OAAO,OAAA;AAAE,6HAAA,+BAA+B,OAAA;AAE1D,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA;AAEzB,uCAKoB;AAJlB,8GAAA,kBAAkB,OAAA;AAClB,4GAAA,gBAAgB,OAAA;AAChB,kHAAA,sBAAsB,OAAA;AACtB,+GAAA,mBAAmB,OAAA;AAGrB,yCAOqB;AANnB,+GAAA,kBAAkB,OAAA;AAClB,wHAAA,2BAA2B,OAAA;AAC3B,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,4GAAA,eAAe,OAAA;AACf,wGAAA,WAAW,OAAA;AAGb,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AAEd,yCAAkF;AAAzE,2HAAA,8BAA8B,OAAA;AAAE,0GAAA,aAAa,OAAA;AAAE,iGAAA,IAAI,OAAA;AAE5D,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AAErB,iCAUiB;AATf,iGAAA,QAAQ,OAAA;AACR,iGAAA,QAAQ,OAAA;AACR,gHAAA,uBAAuB,OAAA;AACvB,oHAAA,2BAA2B,OAAA;AAC3B,iGAAA,QAAQ,OAAA;AACR,uGAAA,cAAc,OAAA;AACd,+FAAA,MAAM,OAAA;AACN,yGAAA,gBAAgB,OAAA;AAChB,gGAAA,OAAO,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers';
|
|
2
|
+
import { LogTypes, FeeTypes } from '@requestnetwork/types';
|
|
3
|
+
/**
|
|
4
|
+
* The function estimates gas fee with EIP-1559.
|
|
5
|
+
* @returns an object containing:
|
|
6
|
+
* - maxFeePerGas: The maximum fee per unit of gas for this transaction.
|
|
7
|
+
* maxFeePerGas = baseFeePerGas + maxPriorityFeePerGas
|
|
8
|
+
* The baseFeePerGas depends on how full the previous blocks were.
|
|
9
|
+
* - maxPriorityFeePerGas: The maximum priority fee per unit of gas for this transaction.
|
|
10
|
+
*/
|
|
11
|
+
declare function normalizeGasFees({ logger, gasPriceMin, gasPriceMax, gasPriceMultiplier, suggestFees, }: {
|
|
12
|
+
logger: LogTypes.ILogger;
|
|
13
|
+
gasPriceMin?: BigNumber;
|
|
14
|
+
gasPriceMax?: BigNumber;
|
|
15
|
+
gasPriceMultiplier?: number;
|
|
16
|
+
suggestFees: () => Promise<FeeTypes.SuggestedFees>;
|
|
17
|
+
}): Promise<FeeTypes.EstimatedGasFees>;
|
|
18
|
+
export { normalizeGasFees };
|
|
19
|
+
//# sourceMappingURL=normalize-gas-fees.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-gas-fees.d.ts","sourceRoot":"","sources":["../src/normalize-gas-fees.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,QAAQ,CAAC;AAG9C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;;;;;GAOG;AACH,iBAAe,gBAAgB,CAAC,EAC9B,MAAM,EACN,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,WAAW,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;CACpD,GAAG,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAgCrC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeGasFees = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const index_1 = require("./index");
|
|
7
|
+
/**
|
|
8
|
+
* The function estimates gas fee with EIP-1559.
|
|
9
|
+
* @returns an object containing:
|
|
10
|
+
* - maxFeePerGas: The maximum fee per unit of gas for this transaction.
|
|
11
|
+
* maxFeePerGas = baseFeePerGas + maxPriorityFeePerGas
|
|
12
|
+
* The baseFeePerGas depends on how full the previous blocks were.
|
|
13
|
+
* - maxPriorityFeePerGas: The maximum priority fee per unit of gas for this transaction.
|
|
14
|
+
*/
|
|
15
|
+
function normalizeGasFees({ logger, gasPriceMin, gasPriceMax, gasPriceMultiplier, suggestFees, }) {
|
|
16
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
try {
|
|
18
|
+
const suggestedFee = yield suggestFees();
|
|
19
|
+
const baseFee = (0, index_1.maxBigNumber)(suggestedFee.baseFee, gasPriceMin || ethers_1.constants.Zero);
|
|
20
|
+
const maxPriorityFeePerGas = (0, index_1.maxBigNumber)(suggestedFee.maxPriorityFee, gasPriceMin || ethers_1.constants.Zero);
|
|
21
|
+
const maxFeePerGasInit = baseFee
|
|
22
|
+
.add(maxPriorityFeePerGas)
|
|
23
|
+
.mul(gasPriceMultiplier || 100)
|
|
24
|
+
.div(100);
|
|
25
|
+
const maxFeePerGas = gasPriceMax
|
|
26
|
+
? (0, index_1.minBigNumber)(maxFeePerGasInit, gasPriceMax)
|
|
27
|
+
: maxFeePerGasInit;
|
|
28
|
+
if (maxPriorityFeePerGas.eq(0) || maxFeePerGas.eq(0)) {
|
|
29
|
+
logger.warn(`normalizeGasFees: maxPriorityFeePerGas or maxFeePerGas too low (maxPriorityFeePerGas: ${maxPriorityFeePerGas.toString()} / maxFeePerGas: ${maxFeePerGas.toString()})`);
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
maxPriorityFeePerGas,
|
|
34
|
+
maxFeePerGas,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
logger.error(`normalizeGasFees error: ${e}`);
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.normalizeGasFees = normalizeGasFees;
|
|
44
|
+
//# sourceMappingURL=normalize-gas-fees.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-gas-fees.js","sourceRoot":"","sources":["../src/normalize-gas-fees.ts"],"names":[],"mappings":";;;;AAAA,mCAA8C;AAE9C,mCAAqD;AAGrD;;;;;;;GAOG;AACH,SAAe,gBAAgB,CAAC,EAC9B,MAAM,EACN,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,WAAW,GAOZ;;QACC,IAAI;YACF,MAAM,YAAY,GAAG,MAAM,WAAW,EAAE,CAAC;YACzC,MAAM,OAAO,GAAG,IAAA,oBAAY,EAAC,YAAY,CAAC,OAAO,EAAE,WAAW,IAAI,kBAAS,CAAC,IAAI,CAAC,CAAC;YAClF,MAAM,oBAAoB,GAAG,IAAA,oBAAY,EACvC,YAAY,CAAC,cAAc,EAC3B,WAAW,IAAI,kBAAS,CAAC,IAAI,CAC9B,CAAC;YAEF,MAAM,gBAAgB,GAAG,OAAO;iBAC7B,GAAG,CAAC,oBAAoB,CAAC;iBACzB,GAAG,CAAC,kBAAkB,IAAI,GAAG,CAAC;iBAC9B,GAAG,CAAC,GAAG,CAAC,CAAC;YACZ,MAAM,YAAY,GAAG,WAAW;gBAC9B,CAAC,CAAC,IAAA,oBAAY,EAAC,gBAAgB,EAAE,WAAW,CAAC;gBAC7C,CAAC,CAAC,gBAAgB,CAAC;YAErB,IAAI,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;gBACpD,MAAM,CAAC,IAAI,CACT,yFAAyF,oBAAoB,CAAC,QAAQ,EAAE,oBAAoB,YAAY,CAAC,QAAQ,EAAE,GAAG,CACvK,CAAC;gBACF,OAAO,EAAE,CAAC;aACX;YAED,OAAO;gBACL,oBAAoB;gBACpB,YAAY;aACb,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,EAAE,CAAC,CAAC;YAC7C,OAAO,EAAE,CAAC;SACX;IACH,CAAC;CAAA;AAEQ,4CAAgB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LogTypes } from '@requestnetwork/types';
|
|
2
|
+
import { providers } from 'ethers';
|
|
3
|
+
type ProviderFactory = (network: string | undefined) => providers.Provider | string;
|
|
4
|
+
/**
|
|
5
|
+
* @param network the network to connect to
|
|
6
|
+
* @param defaultFactory the defaultFactory to use as fallback if needed
|
|
7
|
+
*/
|
|
8
|
+
type CurrentProviderFactory = (network: string | undefined, defaultFactory: ProviderFactory) => providers.Provider | string;
|
|
9
|
+
/**
|
|
10
|
+
* Default API_KEYS configuration, can be overridden using initPaymentDetectionApiKeys
|
|
11
|
+
*/
|
|
12
|
+
declare let providersApiKeys: Record<string, string | (() => string)>;
|
|
13
|
+
/**
|
|
14
|
+
* @param defaultProviderOptions Default Provider Options as specified in https://docs.ethers.io/v5/api/providers/#providers-getDefaultProvider */
|
|
15
|
+
declare const initPaymentDetectionApiKeys: (defaultProviderOptions?: typeof providersApiKeys) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Define default URLs for networks supported by Request payment detection but not by ethers' Infura Provider
|
|
18
|
+
*/
|
|
19
|
+
declare const networkRpcs: Record<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Override the default providerFactory, which relies mainly on Infura.
|
|
22
|
+
* @param providerFactory if not specify, will reset to the default factory
|
|
23
|
+
*/
|
|
24
|
+
declare const setProviderFactory: (providerFactory?: CurrentProviderFactory) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Returns a Web3 Provider for the given `network`.
|
|
27
|
+
*
|
|
28
|
+
* Configuration options:
|
|
29
|
+
* - Specify `RN_WEB3_RPC_URL_[NETWORK]` environment variable to override the default behaviour
|
|
30
|
+
* - Specify `RN_INFURA_KEY` to override the default Infura API KEY (recommended)
|
|
31
|
+
* - Use `initPaymentDetectionApiKeys` to override Infura API KEY when `RN_INFURA_KEY` is not usable
|
|
32
|
+
* - Use `setProviderFactory` for more complex configurations with multiple networks
|
|
33
|
+
*
|
|
34
|
+
* @param network the blockchain network. See https://chainid.network/chains.json `network` field for reference
|
|
35
|
+
*/
|
|
36
|
+
declare const getDefaultProvider: (network?: string) => providers.Provider;
|
|
37
|
+
declare const getCeloProvider: () => providers.Provider;
|
|
38
|
+
declare const isEip1559Supported: (provider: providers.Provider | providers.JsonRpcProvider, logger?: LogTypes.ILogger) => Promise<boolean>;
|
|
39
|
+
export { setProviderFactory, initPaymentDetectionApiKeys, isEip1559Supported, getDefaultProvider, getCeloProvider, networkRpcs, };
|
|
40
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +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,EAAoB,MAAM,QAAQ,CAAC;AAErD,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,CAsBvC,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,CAejB,CAAC;AAEF,OAAO,EACL,kBAAkB,EAClB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,WAAW,GACZ,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.networkRpcs = exports.getCeloProvider = exports.getDefaultProvider = exports.isEip1559Supported = exports.initPaymentDetectionApiKeys = exports.setProviderFactory = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
let warned = false;
|
|
7
|
+
/**
|
|
8
|
+
* Default API_KEYS configuration, can be overridden using initPaymentDetectionApiKeys
|
|
9
|
+
*/
|
|
10
|
+
let providersApiKeys = {
|
|
11
|
+
// fallback to Ethers v5 default projectId
|
|
12
|
+
infura: () => process.env.RN_INFURA_KEY || '84842078b09946638c03157f83405213',
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @param defaultProviderOptions Default Provider Options as specified in https://docs.ethers.io/v5/api/providers/#providers-getDefaultProvider */
|
|
16
|
+
const initPaymentDetectionApiKeys = (defaultProviderOptions) => {
|
|
17
|
+
providersApiKeys = Object.assign(Object.assign({}, providersApiKeys), defaultProviderOptions);
|
|
18
|
+
};
|
|
19
|
+
exports.initPaymentDetectionApiKeys = initPaymentDetectionApiKeys;
|
|
20
|
+
/**
|
|
21
|
+
* Define default URLs for networks supported by Request payment detection but not by ethers' Infura Provider
|
|
22
|
+
*/
|
|
23
|
+
const networkRpcs = {
|
|
24
|
+
private: ethers_1.providers.JsonRpcProvider.defaultUrl(),
|
|
25
|
+
matic: 'https://polygon-rpc.com/',
|
|
26
|
+
fantom: 'https://rpc.ftm.tools',
|
|
27
|
+
fuse: 'https://rpc.fuse.io',
|
|
28
|
+
bsctest: 'https://data-seed-prebsc-1-s1.binance.org:8545',
|
|
29
|
+
bsc: 'https://bsc-dataseed1.binance.org/',
|
|
30
|
+
xdai: 'https://rpc.ankr.com/gnosis',
|
|
31
|
+
celo: 'https://forno.celo.org',
|
|
32
|
+
'arbitrum-rinkeby': 'https://rinkeby.arbitrum.io/rpc',
|
|
33
|
+
'arbitrum-one': 'https://arb1.arbitrum.io/rpc',
|
|
34
|
+
avalanche: 'https://api.avax.network/ext/bc/C/rpc',
|
|
35
|
+
optimism: 'https://mainnet.optimism.io',
|
|
36
|
+
moonbeam: 'https://moonbeam.public.blastapi.io',
|
|
37
|
+
tombchain: 'https://rpc.tombchain.com/',
|
|
38
|
+
mantle: 'https://rpc.mantle.xyz/',
|
|
39
|
+
'mantle-testnet': 'https://rpc.testnet.mantle.xyz/',
|
|
40
|
+
core: 'https://rpc.coredao.org/',
|
|
41
|
+
zksynceratestnet: 'https://testnet.era.zksync.dev',
|
|
42
|
+
zksyncera: 'https://mainnet.era.zksync.io',
|
|
43
|
+
sepolia: 'https://rpc.sepolia.org/',
|
|
44
|
+
base: 'https://mainnet.base.org/',
|
|
45
|
+
};
|
|
46
|
+
exports.networkRpcs = networkRpcs;
|
|
47
|
+
/**
|
|
48
|
+
* @see getDefaultProvider
|
|
49
|
+
*/
|
|
50
|
+
const defaultProviderFactory = (network) => {
|
|
51
|
+
if (!network) {
|
|
52
|
+
network = 'homestead';
|
|
53
|
+
}
|
|
54
|
+
// Returns environment variable override
|
|
55
|
+
const envVar = (process === null || process === void 0 ? void 0 : process.env) ? process.env[`RN_WEB3_RPC_URL_${network.toUpperCase()}`] : null;
|
|
56
|
+
if (envVar) {
|
|
57
|
+
return envVar;
|
|
58
|
+
}
|
|
59
|
+
// check default RPCs
|
|
60
|
+
if (networkRpcs[network]) {
|
|
61
|
+
return networkRpcs[network];
|
|
62
|
+
}
|
|
63
|
+
// use Infura, if supported
|
|
64
|
+
try {
|
|
65
|
+
// try getting the URL for the given network. Will throw if not supported.
|
|
66
|
+
ethers_1.providers.InfuraProvider.getUrl(ethers_1.providers.getNetwork(network), {});
|
|
67
|
+
const apiKey = typeof providersApiKeys.infura === 'function'
|
|
68
|
+
? providersApiKeys.infura()
|
|
69
|
+
: providersApiKeys.infura;
|
|
70
|
+
if (!apiKey && !warned) {
|
|
71
|
+
console.warn(`No API Key specified for Infura, using ethers default API key.
|
|
72
|
+
This is not recommended for Production environments.
|
|
73
|
+
To override Infura's default api key, use RN_INFURA_KEY environment variable, or call
|
|
74
|
+
initPaymentDetectionApiKeys({ infura: () => "myApiKey" });
|
|
75
|
+
`);
|
|
76
|
+
warned = true;
|
|
77
|
+
}
|
|
78
|
+
return new ethers_1.providers.InfuraProvider(network, apiKey);
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
// suppress errors
|
|
82
|
+
}
|
|
83
|
+
if (!warned) {
|
|
84
|
+
console.warn(`No provider is specified for network ${network}, using ethers default provider.
|
|
85
|
+
This is not recommended for Production environments.
|
|
86
|
+
Use setProviderFactory to override the default provider`);
|
|
87
|
+
warned = true;
|
|
88
|
+
}
|
|
89
|
+
// use getDefaultProvider to keep the original behaviour
|
|
90
|
+
return ethers_1.providers.getDefaultProvider(network, providersApiKeys);
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Defines the behaviour to obtain a Provider for a given Network.
|
|
94
|
+
* May be overridden using setProviderFactory
|
|
95
|
+
*/
|
|
96
|
+
let currentProviderFactory = defaultProviderFactory;
|
|
97
|
+
/**
|
|
98
|
+
* Override the default providerFactory, which relies mainly on Infura.
|
|
99
|
+
* @param providerFactory if not specify, will reset to the default factory
|
|
100
|
+
*/
|
|
101
|
+
const setProviderFactory = (providerFactory) => {
|
|
102
|
+
currentProviderFactory = providerFactory || defaultProviderFactory;
|
|
103
|
+
};
|
|
104
|
+
exports.setProviderFactory = setProviderFactory;
|
|
105
|
+
/**
|
|
106
|
+
* Returns a Web3 Provider for the given `network`.
|
|
107
|
+
*
|
|
108
|
+
* Configuration options:
|
|
109
|
+
* - Specify `RN_WEB3_RPC_URL_[NETWORK]` environment variable to override the default behaviour
|
|
110
|
+
* - Specify `RN_INFURA_KEY` to override the default Infura API KEY (recommended)
|
|
111
|
+
* - Use `initPaymentDetectionApiKeys` to override Infura API KEY when `RN_INFURA_KEY` is not usable
|
|
112
|
+
* - Use `setProviderFactory` for more complex configurations with multiple networks
|
|
113
|
+
*
|
|
114
|
+
* @param network the blockchain network. See https://chainid.network/chains.json `network` field for reference
|
|
115
|
+
*/
|
|
116
|
+
const getDefaultProvider = (network) => {
|
|
117
|
+
const provider = currentProviderFactory(network, defaultProviderFactory);
|
|
118
|
+
if (typeof provider === 'string') {
|
|
119
|
+
return new ethers_1.providers.StaticJsonRpcProvider(provider);
|
|
120
|
+
}
|
|
121
|
+
return provider;
|
|
122
|
+
};
|
|
123
|
+
exports.getDefaultProvider = getDefaultProvider;
|
|
124
|
+
const getCeloProvider = () => {
|
|
125
|
+
const provider = new ethers_1.providers.JsonRpcProvider('https://forno.celo.org');
|
|
126
|
+
const originalBlockFormatter = provider.formatter._block;
|
|
127
|
+
provider.formatter._block = (value, format) => {
|
|
128
|
+
return originalBlockFormatter(Object.assign({ gasLimit: ethers_1.constants.Zero }, value), format);
|
|
129
|
+
};
|
|
130
|
+
return provider;
|
|
131
|
+
};
|
|
132
|
+
exports.getCeloProvider = getCeloProvider;
|
|
133
|
+
const isEip1559Supported = (provider, logger) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
134
|
+
try {
|
|
135
|
+
yield provider.send('eth_feeHistory', [
|
|
136
|
+
ethers_1.utils.hexStripZeros(ethers_1.utils.hexlify(1)),
|
|
137
|
+
'latest',
|
|
138
|
+
[],
|
|
139
|
+
]);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
logger &&
|
|
144
|
+
logger.warn('This RPC provider does not support the "eth_feeHistory" method: switching to legacy gas price');
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
exports.isEip1559Supported = isEip1559Supported;
|
|
149
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"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"}
|
package/dist/retry.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
declare const _default: (target: any, { context, maxRetries, retryDelay, }?: {
|
|
2
|
-
context?: any;
|
|
3
|
-
maxRetries?: number | undefined;
|
|
4
|
-
retryDelay?: number | undefined;
|
|
5
|
-
}) => any;
|
|
6
1
|
/**
|
|
7
2
|
* A method that retries a function a defined amount of times if it fails.
|
|
8
3
|
*
|
|
@@ -11,6 +6,15 @@ declare const _default: (target: any, { context, maxRetries, retryDelay, }?: {
|
|
|
11
6
|
* @param [options.context] The context to run the function
|
|
12
7
|
* @param [options.maxRetries=DEFAULT_MAX_RETRIES] The maximum amount of retries for the function
|
|
13
8
|
* @param [options.retryDelay=DEFAULT_RETRY_DELAY] The delay between retries
|
|
9
|
+
* @param [options.exponentialBackoffDelay=DEFAULT_EXPONENTIAL_BACKOFF_DELAY] The exponential backoff delay increment
|
|
10
|
+
* @param [options.maxExponentialBackoffDelay=DEFAULT_MAX_EXPONENTIAL_BACKOFF_DELAY] The maximum exponential backoff delay allowed
|
|
14
11
|
*/
|
|
15
|
-
|
|
12
|
+
declare const retry: <TParams extends unknown[], TReturn>(target: (...params: TParams) => TReturn | Promise<TReturn>, { context, maxRetries, retryDelay, exponentialBackoffDelay, maxExponentialBackoffDelay, }?: {
|
|
13
|
+
context?: unknown;
|
|
14
|
+
maxRetries?: number | undefined;
|
|
15
|
+
retryDelay?: number | undefined;
|
|
16
|
+
exponentialBackoffDelay?: number | undefined;
|
|
17
|
+
maxExponentialBackoffDelay?: number | undefined;
|
|
18
|
+
}) => (...params: TParams) => Promise<TReturn>;
|
|
19
|
+
export { retry };
|
|
16
20
|
//# sourceMappingURL=retry.d.ts.map
|
package/dist/retry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;GAUG;AACH,QAAA,MAAM,KAAK;;;;;;8CAoDV,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
|