@requestnetwork/utils 0.36.1-next.1854 → 0.36.1-next.1857
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 +4 -9
- package/dist/amount.d.ts.map +1 -1
- package/dist/amount.js +13 -17
- package/dist/amount.js.map +1 -1
- package/dist/bignumber.d.ts +5 -5
- package/dist/bignumber.d.ts.map +1 -1
- package/dist/bignumber.js +5 -3
- package/dist/bignumber.js.map +1 -1
- package/dist/cached-throttle.d.ts +2 -2
- package/dist/cached-throttle.d.ts.map +1 -1
- package/dist/cached-throttle.js +0 -1
- 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 +6 -10
- 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 +15 -19
- package/dist/crypto/ec-utils.js.map +1 -1
- package/dist/crypto.d.ts +3 -27
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +22 -17
- 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 +12 -16
- package/dist/encryption.js.map +1 -1
- package/dist/estimate-gas-fees.d.ts +1 -1
- package/dist/estimate-gas-fees.d.ts.map +1 -1
- package/dist/estimate-gas-fees.js +4 -3
- package/dist/estimate-gas-fees.js.map +1 -1
- package/dist/identity.d.ts +4 -9
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +7 -11
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +12 -80
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -21
- package/dist/index.js.map +1 -1
- package/dist/providers.d.ts +26 -8
- package/dist/providers.d.ts.map +1 -1
- package/dist/providers.js +6 -7
- package/dist/providers.js.map +1 -1
- package/dist/retry.d.ts +2 -2
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +0 -1
- package/dist/retry.js.map +1 -1
- package/dist/signature.d.ts +2 -7
- package/dist/signature.d.ts.map +1 -1
- package/dist/signature.js +12 -16
- 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 +2 -1
- package/dist/simple-logger.js.map +1 -1
- package/dist/utils.d.ts +1 -12
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +12 -16
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,24 +3,6 @@
|
|
|
3
3
|
`@requestnetwork/utils` is a typescript library part of the [Request Network protocol](https://github.com/RequestNetwork/requestNetwork).
|
|
4
4
|
It is a collection of tools shared between the @requestnetwork packages.
|
|
5
5
|
|
|
6
|
-
- Elliptic curve crypto and signature
|
|
7
|
-
- crypto.normalizeKeccak256Hash()
|
|
8
|
-
- crypto.ecUtils.getAddressFromPrivateKey()
|
|
9
|
-
- crypto.ecUtils.recover()
|
|
10
|
-
- crypto.ecUtils.sign()
|
|
11
|
-
- signature.getIdentityFromSignatureParams()
|
|
12
|
-
- signature.recover()
|
|
13
|
-
- signature.sign()
|
|
14
|
-
- Identity
|
|
15
|
-
- identity.areEqual()
|
|
16
|
-
- identity.normalizeIdentityValue()
|
|
17
|
-
- isString
|
|
18
|
-
- Miscellaneous
|
|
19
|
-
- deepCopy()
|
|
20
|
-
- deepSort()
|
|
21
|
-
- flatten2DimensionsArray()
|
|
22
|
-
- getCurrentTimestampInSecond()
|
|
23
|
-
|
|
24
6
|
## Installation
|
|
25
7
|
|
|
26
8
|
```bash
|
|
@@ -30,9 +12,9 @@ npm install @requestnetwork/utils
|
|
|
30
12
|
## Usage
|
|
31
13
|
|
|
32
14
|
```javascript
|
|
33
|
-
import
|
|
15
|
+
import { normalizeKeccak256Hash } from '@requestnetwork/utils';
|
|
34
16
|
|
|
35
|
-
const hash =
|
|
17
|
+
const hash = normalizeKeccak256Hash({ exampleData: true });
|
|
36
18
|
```
|
|
37
19
|
|
|
38
20
|
## Contributing
|
package/dist/amount.d.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { RequestLogicTypes } from '@requestnetwork/types';
|
|
2
2
|
import { BigNumber } from 'ethers';
|
|
3
|
-
declare const _default: {
|
|
4
|
-
add: typeof add;
|
|
5
|
-
isValid: typeof isValid;
|
|
6
|
-
reduce: typeof reduce;
|
|
7
|
-
};
|
|
8
3
|
/**
|
|
9
4
|
* Function to manage amounts
|
|
10
5
|
*/
|
|
11
|
-
export
|
|
6
|
+
export { addAmount, isValidAmount, reduceAmount };
|
|
12
7
|
/**
|
|
13
8
|
* Function to check if the amount is valid (representation of a positive integer)
|
|
14
9
|
*
|
|
@@ -16,7 +11,7 @@ export default _default;
|
|
|
16
11
|
*
|
|
17
12
|
* @returns boolean true if amount is a valid amount
|
|
18
13
|
*/
|
|
19
|
-
declare function
|
|
14
|
+
declare function isValidAmount(amount: RequestLogicTypes.Amount | BigNumber): boolean;
|
|
20
15
|
/**
|
|
21
16
|
* Function to add an amount by another
|
|
22
17
|
*
|
|
@@ -25,7 +20,7 @@ declare function isValid(amount: RequestLogicTypes.Amount | BigNumber): boolean;
|
|
|
25
20
|
*
|
|
26
21
|
* @returns string the new amount in a string format
|
|
27
22
|
*/
|
|
28
|
-
declare function
|
|
23
|
+
declare function addAmount(amount: RequestLogicTypes.Amount, delta: RequestLogicTypes.Amount): string;
|
|
29
24
|
/**
|
|
30
25
|
* Function to reduce an amount by another
|
|
31
26
|
*
|
|
@@ -36,5 +31,5 @@ declare function add(amount: RequestLogicTypes.Amount, delta: RequestLogicTypes.
|
|
|
36
31
|
*
|
|
37
32
|
* @returns string the new amount in a string format
|
|
38
33
|
*/
|
|
39
|
-
declare function
|
|
34
|
+
declare function reduceAmount(amount: RequestLogicTypes.Amount, delta: RequestLogicTypes.Amount): string;
|
|
40
35
|
//# sourceMappingURL=amount.d.ts.map
|
package/dist/amount.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../src/amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC
|
|
1
|
+
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../src/amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;AAIlD;;;;;;GAMG;AACH,iBAAS,aAAa,CAAC,MAAM,EAAE,iBAAiB,CAAC,MAAM,GAAG,SAAS,GAAG,OAAO,CAK5E;AAED;;;;;;;GAOG;AACH,iBAAS,SAAS,CAAC,MAAM,EAAE,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,iBAAiB,CAAC,MAAM,GAAG,MAAM,CAW5F;AAED;;;;;;;;;GASG;AACH,iBAAS,YAAY,CAAC,MAAM,EAAE,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,iBAAiB,CAAC,MAAM,GAAG,MAAM,CAiB/F"}
|
package/dist/amount.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reduceAmount = exports.isValidAmount = exports.addAmount = void 0;
|
|
3
4
|
const utils_1 = require("./utils");
|
|
4
5
|
const ethers_1 = require("ethers");
|
|
5
|
-
/**
|
|
6
|
-
* Function to manage amounts
|
|
7
|
-
*/
|
|
8
|
-
exports.default = {
|
|
9
|
-
add,
|
|
10
|
-
isValid,
|
|
11
|
-
reduce,
|
|
12
|
-
};
|
|
13
6
|
const regexInteger = RegExp(/^[\d]+$/);
|
|
14
7
|
/**
|
|
15
8
|
* Function to check if the amount is valid (representation of a positive integer)
|
|
@@ -18,10 +11,11 @@ const regexInteger = RegExp(/^[\d]+$/);
|
|
|
18
11
|
*
|
|
19
12
|
* @returns boolean true if amount is a valid amount
|
|
20
13
|
*/
|
|
21
|
-
function
|
|
22
|
-
return ((utils_1.
|
|
14
|
+
function isValidAmount(amount) {
|
|
15
|
+
return (((0, utils_1.isString)(amount) && regexInteger.test(amount)) ||
|
|
23
16
|
(typeof amount === 'number' && Number.isSafeInteger(Number(amount)) && Number(amount) >= 0));
|
|
24
17
|
}
|
|
18
|
+
exports.isValidAmount = isValidAmount;
|
|
25
19
|
/**
|
|
26
20
|
* Function to add an amount by another
|
|
27
21
|
*
|
|
@@ -30,17 +24,18 @@ function isValid(amount) {
|
|
|
30
24
|
*
|
|
31
25
|
* @returns string the new amount in a string format
|
|
32
26
|
*/
|
|
33
|
-
function
|
|
34
|
-
if (!
|
|
27
|
+
function addAmount(amount, delta) {
|
|
28
|
+
if (!isValidAmount(amount)) {
|
|
35
29
|
throw Error('amount must represent a positive integer');
|
|
36
30
|
}
|
|
37
|
-
if (!
|
|
31
|
+
if (!isValidAmount(delta)) {
|
|
38
32
|
throw Error('delta must represent a positive integer');
|
|
39
33
|
}
|
|
40
34
|
const amountBN = ethers_1.BigNumber.from(amount);
|
|
41
35
|
const deltaBN = ethers_1.BigNumber.from(delta);
|
|
42
36
|
return amountBN.add(deltaBN).toString();
|
|
43
37
|
}
|
|
38
|
+
exports.addAmount = addAmount;
|
|
44
39
|
/**
|
|
45
40
|
* Function to reduce an amount by another
|
|
46
41
|
*
|
|
@@ -51,20 +46,21 @@ function add(amount, delta) {
|
|
|
51
46
|
*
|
|
52
47
|
* @returns string the new amount in a string format
|
|
53
48
|
*/
|
|
54
|
-
function
|
|
55
|
-
if (!
|
|
49
|
+
function reduceAmount(amount, delta) {
|
|
50
|
+
if (!isValidAmount(amount)) {
|
|
56
51
|
throw Error('amount must represent a positive integer');
|
|
57
52
|
}
|
|
58
|
-
if (!
|
|
53
|
+
if (!isValidAmount(delta)) {
|
|
59
54
|
throw Error('delta must represent a positive integer');
|
|
60
55
|
}
|
|
61
56
|
const amountBN = ethers_1.BigNumber.from(amount);
|
|
62
57
|
const deltaBN = ethers_1.BigNumber.from(delta);
|
|
63
58
|
const newAmount = amountBN.sub(deltaBN).toString();
|
|
64
59
|
// Check if the new amount is valid (basically it is not negative)
|
|
65
|
-
if (!
|
|
60
|
+
if (!isValidAmount(newAmount)) {
|
|
66
61
|
throw Error('result of reduce is not valid');
|
|
67
62
|
}
|
|
68
63
|
return newAmount;
|
|
69
64
|
}
|
|
65
|
+
exports.reduceAmount = reduceAmount;
|
|
70
66
|
//# sourceMappingURL=amount.js.map
|
package/dist/amount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../src/amount.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../src/amount.ts"],"names":[],"mappings":";;;AACA,mCAAmC;AAEnC,mCAAmC;AAOnC,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AAEvC;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,MAA4C;IACjE,OAAO,CACL,CAAC,IAAA,gBAAQ,EAAC,MAAM,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;QACzD,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAC5F,CAAC;AACJ,CAAC;AAhBmB,sCAAa;AAkBjC;;;;;;;GAOG;AACH,SAAS,SAAS,CAAC,MAAgC,EAAE,K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
|
|
6
|
-
export
|
|
2
|
+
/** Returns the minimum of two big numbers */
|
|
3
|
+
declare const minBigNumber: (a: BigNumberish, b: BigNumberish) => BigNumber;
|
|
4
|
+
/** Returns the maximum of two big numbers */
|
|
5
|
+
declare const maxBigNumber: (a: BigNumberish, b: BigNumberish) => BigNumber;
|
|
6
|
+
export { minBigNumber, maxBigNumber };
|
|
7
7
|
//# sourceMappingURL=bignumber.d.ts.map
|
package/dist/bignumber.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bignumber.d.ts","sourceRoot":"","sources":["../src/bignumber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC
|
|
1
|
+
{"version":3,"file":"bignumber.d.ts","sourceRoot":"","sources":["../src/bignumber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEjD,6CAA6C;AAC7C,QAAA,MAAM,YAAY,MAAO,YAAY,KAAK,YAAY,KAAG,SACQ,CAAC;AAElE,6CAA6C;AAC7C,QAAA,MAAM,YAAY,MAAO,YAAY,KAAK,YAAY,KAAG,SACQ,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/bignumber.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maxBigNumber = exports.minBigNumber = void 0;
|
|
3
4
|
const ethers_1 = require("ethers");
|
|
4
5
|
/** Returns the minimum of two big numbers */
|
|
5
|
-
const
|
|
6
|
+
const minBigNumber = (a, b) => ethers_1.BigNumber.from(a).lt(b) ? ethers_1.BigNumber.from(a) : ethers_1.BigNumber.from(b);
|
|
7
|
+
exports.minBigNumber = minBigNumber;
|
|
6
8
|
/** Returns the maximum of two big numbers */
|
|
7
|
-
const
|
|
8
|
-
exports.
|
|
9
|
+
const maxBigNumber = (a, b) => ethers_1.BigNumber.from(a).gt(b) ? ethers_1.BigNumber.from(a) : ethers_1.BigNumber.from(b);
|
|
10
|
+
exports.maxBigNumber = maxBigNumber;
|
|
9
11
|
//# sourceMappingURL=bignumber.js.map
|
package/dist/bignumber.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bignumber.js","sourceRoot":"","sources":["../src/bignumber.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bignumber.js","sourceRoot":"","sources":["../src/bignumber.ts"],"names":[],"mappings":";;;AAAA,mCAAiD;AAEjD,6CAA6C;AAC7C,MAAM,YAAY,GAAG,CAAC,CAAe,EAAE,CAAe,EAAa,EAAE,CACnE,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAMzD,oCAAY;AAJrB,6CAA6C;AAC7C,MAAM,YAAY,GAAG,CAAC,CAAe,EAAE,CAAe,EAAa,EAAE,CACnE,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAE3C,oCAAY"}
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* @param target The target function
|
|
6
6
|
* @param minimumDelay The minimum delay between calls to the target function in milliseconds
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
export
|
|
8
|
+
declare const cachedThrottle: <TParams extends unknown[], TReturn>(target: (...params: TParams) => Promise<TReturn>, minimumDelay: number) => (...params: TParams) => Promise<TReturn>;
|
|
9
|
+
export { cachedThrottle };
|
|
10
10
|
//# sourceMappingURL=cached-throttle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached-throttle.d.ts","sourceRoot":"","sources":["../src/cached-throttle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,
|
|
1
|
+
{"version":3,"file":"cached-throttle.d.ts","sourceRoot":"","sources":["../src/cached-throttle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,QAAA,MAAM,cAAc,uGAEJ,MAAM,6CAoBrB,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/cached-throttle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached-throttle.js","sourceRoot":"","sources":["../src/cached-throttle.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"cached-throttle.js","sourceRoot":"","sources":["../src/cached-throttle.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,CACrB,MAAgD,EAChD,YAAoB,EACwB,EAAE;IAC9C,IAAI,CAAC,CAAC,MAAM,YAAY,QAAQ,CAAC,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;KAClD;IAED,2BAA2B;IAC3B,IAAI,cAAc,GAA4B,IAAI,CAAC;IAEnD,wCAAwC;IACxC,IAAI,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAExC,OAAO,CAAC,GAAG,IAAa,EAAoB,EAAE;QAC5C,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ,GAAG,YAAY,EAAE;YAC5D,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACtB,cAAc,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;SAClC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC,CAAC;AAEO,wCAAc"}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
declare const _default: {
|
|
3
|
-
decryptWithAes256cbc: typeof decryptWithAes256cbc;
|
|
4
|
-
decryptWithAes256gcm: typeof decryptWithAes256gcm;
|
|
5
|
-
encryptWithAes256cbc: typeof encryptWithAes256cbc;
|
|
6
|
-
encryptWithAes256gcm: typeof encryptWithAes256gcm;
|
|
7
|
-
random32Bytes: typeof random32Bytes;
|
|
8
|
-
};
|
|
9
2
|
/**
|
|
10
3
|
* Functions to manage native crypto functions of nodeJs
|
|
11
4
|
*/
|
|
12
|
-
export
|
|
5
|
+
export { decryptWithAes256cbc, decryptWithAes256gcm, encryptWithAes256cbc, encryptWithAes256gcm, random32Bytes, };
|
|
13
6
|
/**
|
|
14
7
|
* Generates 32 cryptographically strong pseudo-random bytes
|
|
15
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-wrapper.d.ts","sourceRoot":"","sources":["../../src/crypto/crypto-wrapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto-wrapper.d.ts","sourceRoot":"","sources":["../../src/crypto/crypto-wrapper.ts"],"names":[],"mappings":";AAEA;;GAEG;AACH,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,GACd,CAAC;AAWF;;;;GAIG;AACH,iBAAe,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAG9C;AAED;;;;;;;GAOG;AACH,iBAAe,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAY9E;AAED;;;;;;;GAOG;AACH,iBAAe,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAY9E;AAED;;;;;;;GAOG;AACH,iBAAe,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAaxF;AAED;;;;;;;GAOG;AACH,iBAAe,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAkBxF"}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.random32Bytes = exports.encryptWithAes256gcm = exports.encryptWithAes256cbc = exports.decryptWithAes256gcm = exports.decryptWithAes256cbc = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const crypto_1 = require("crypto");
|
|
5
|
-
/**
|
|
6
|
-
* Functions to manage native crypto functions of nodeJs
|
|
7
|
-
*/
|
|
8
|
-
exports.default = {
|
|
9
|
-
decryptWithAes256cbc,
|
|
10
|
-
decryptWithAes256gcm,
|
|
11
|
-
encryptWithAes256cbc,
|
|
12
|
-
encryptWithAes256gcm,
|
|
13
|
-
random32Bytes,
|
|
14
|
-
};
|
|
15
6
|
// Algorithm name used for aes256-cbc encryption with the package 'crypto'
|
|
16
7
|
const AES_256_CBC_ALGORITHM = 'aes-256-cbc';
|
|
17
8
|
// Algorithm name used for aes256-gcm encryption with the package 'crypto'
|
|
@@ -30,6 +21,7 @@ function random32Bytes() {
|
|
|
30
21
|
return randomBytes(32);
|
|
31
22
|
});
|
|
32
23
|
}
|
|
24
|
+
exports.random32Bytes = random32Bytes;
|
|
33
25
|
/**
|
|
34
26
|
* Encrypts a buffer using AES-256-cbc plus a random Initialization Vector (IV)
|
|
35
27
|
*
|
|
@@ -50,6 +42,7 @@ function encryptWithAes256cbc(data, key) {
|
|
|
50
42
|
return Buffer.concat([iv, encrypted, cipher.final()]);
|
|
51
43
|
});
|
|
52
44
|
}
|
|
45
|
+
exports.encryptWithAes256cbc = encryptWithAes256cbc;
|
|
53
46
|
/**
|
|
54
47
|
* Encrypts a buffer using AES-256-gcm plus a random Initialization Vector (IV)
|
|
55
48
|
*
|
|
@@ -71,6 +64,7 @@ function encryptWithAes256gcm(data, key) {
|
|
|
71
64
|
return Buffer.concat([iv, authTag, encrypted, final]);
|
|
72
65
|
});
|
|
73
66
|
}
|
|
67
|
+
exports.encryptWithAes256gcm = encryptWithAes256gcm;
|
|
74
68
|
/**
|
|
75
69
|
* Decrypts an encrypted buffer using AES-256-cbc plus a random Initialization Vector (IV)
|
|
76
70
|
*
|
|
@@ -92,6 +86,7 @@ function decryptWithAes256cbc(encryptedAndIv, key) {
|
|
|
92
86
|
return Buffer.concat([decipher.update(encryptedData), decipher.final()]);
|
|
93
87
|
});
|
|
94
88
|
}
|
|
89
|
+
exports.decryptWithAes256cbc = decryptWithAes256cbc;
|
|
95
90
|
/**
|
|
96
91
|
* Decrypts an encrypted buffer using AES-256-gcm plus a random Initialization Vector (IV)
|
|
97
92
|
*
|
|
@@ -115,6 +110,7 @@ function decryptWithAes256gcm(encryptedAndIv, key) {
|
|
|
115
110
|
return Buffer.concat([decipher.update(encryptedData), decipher.final()]);
|
|
116
111
|
});
|
|
117
112
|
}
|
|
113
|
+
exports.decryptWithAes256gcm = decryptWithAes256gcm;
|
|
118
114
|
/**
|
|
119
115
|
* Generates N cryptographically strong pseudo-random bytes
|
|
120
116
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-wrapper.js","sourceRoot":"","sources":["../../src/crypto/crypto-wrapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto-wrapper.js","sourceRoot":"","sources":["../../src/crypto/crypto-wrapper.ts"],"names":[],"mappings":";;;;AAAA,mCAA4F;AAa5F,0EAA0E;AAC1E,MAAM,qBAAqB,GAAG,aAAa,CAAC;AAC5C,0EAA0E;AAC1E,MAAM,qBAAqB,GAAG,aAAa,CAAC;AAE5C,oFAAoF;AACpF,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,eAAe,GAAG,EAAE,CAA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SAAe,WAAW,CAAC,CAAS;;QAClC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAO,EAAE;YAC1C,IAAA,oBAAiB,EAAC,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;gBACrC,IAAI,KAAK,EAAE;oBACT,OAAO,MAAM,CAAC,kCAAkC,KAAK,EAAE,CAAC,CAAC;iBAC1D;gBACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CAAA"}
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
declare const _default: {
|
|
2
|
-
decrypt: typeof decrypt;
|
|
3
|
-
encrypt: typeof encrypt;
|
|
4
|
-
getAddressFromPrivateKey: typeof getAddressFromPrivateKey;
|
|
5
|
-
getAddressFromPublicKey: typeof getAddressFromPublicKey;
|
|
6
|
-
recover: typeof recover;
|
|
7
|
-
sign: typeof sign;
|
|
8
|
-
};
|
|
9
1
|
/**
|
|
10
2
|
* Function to manage Elliptic-curve cryptography
|
|
11
3
|
*/
|
|
12
|
-
export
|
|
4
|
+
export { ecDecrypt, ecEncrypt, getAddressFromPrivateKey, getAddressFromPublicKey, ecRecover, ecSign, };
|
|
13
5
|
/**
|
|
14
6
|
* Function to derive the address from an EC private key
|
|
15
7
|
*
|
|
@@ -27,13 +19,13 @@ declare function getAddressFromPrivateKey(privateKey: string): string;
|
|
|
27
19
|
*/
|
|
28
20
|
declare function getAddressFromPublicKey(publicKey: string): string;
|
|
29
21
|
/**
|
|
30
|
-
* Function
|
|
22
|
+
* Function ecSigndata with ECDSA
|
|
31
23
|
*
|
|
32
24
|
* @param data the data to sign
|
|
33
25
|
*
|
|
34
26
|
* @returns the signature
|
|
35
27
|
*/
|
|
36
|
-
declare function
|
|
28
|
+
declare function ecSign(privateKey: string, data: string): string;
|
|
37
29
|
/**
|
|
38
30
|
* Function to recover address from a signature
|
|
39
31
|
*
|
|
@@ -42,7 +34,7 @@ declare function sign(privateKey: string, data: string): string;
|
|
|
42
34
|
*
|
|
43
35
|
* @returns the address
|
|
44
36
|
*/
|
|
45
|
-
declare function
|
|
37
|
+
declare function ecRecover(signature: string, data: string): string;
|
|
46
38
|
/**
|
|
47
39
|
* Function to encrypt data with a public key
|
|
48
40
|
*
|
|
@@ -51,7 +43,7 @@ declare function recover(signature: string, data: string): string;
|
|
|
51
43
|
*
|
|
52
44
|
* @returns the encrypted data
|
|
53
45
|
*/
|
|
54
|
-
declare function
|
|
46
|
+
declare function ecEncrypt(publicKey: string, data: string): Promise<string>;
|
|
55
47
|
/**
|
|
56
48
|
* Function to decrypt data with a public key
|
|
57
49
|
*
|
|
@@ -60,5 +52,5 @@ declare function encrypt(publicKey: string, data: string): Promise<string>;
|
|
|
60
52
|
*
|
|
61
53
|
* @returns the decrypted data
|
|
62
54
|
*/
|
|
63
|
-
declare function
|
|
55
|
+
declare function ecDecrypt(privateKey: string, data: string): Promise<string>;
|
|
64
56
|
//# sourceMappingURL=ec-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ec-utils.d.ts","sourceRoot":"","sources":["../../src/crypto/ec-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ec-utils.d.ts","sourceRoot":"","sources":["../../src/crypto/ec-utils.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,OAAO,EACL,SAAS,EACT,SAAS,EACT,wBAAwB,EACxB,uBAAuB,EACvB,SAAS,EACT,MAAM,GACP,CAAC;AAEF;;;;;;GAMG;AACH,iBAAS,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAgB5D;AAED;;;;;;GAMG;AACH,iBAAS,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAa1D;AAED;;;;;;GAMG;AACH,iBAAS,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAcxD;AAED;;;;;;;GAOG;AACH,iBAAS,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CA8B1D;AAED;;;;;;;GAOG;AACH,iBAAe,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBzE;AAED;;;;;;;GAOG;AACH,iBAAe,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAyB1E"}
|
package/dist/crypto/ec-utils.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ecSign = exports.ecRecover = exports.getAddressFromPublicKey = exports.getAddressFromPrivateKey = exports.ecEncrypt = exports.ecDecrypt = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const EcCrypto = require("eccrypto");
|
|
5
6
|
const secp256k1_1 = require("secp256k1");
|
|
6
7
|
const ethers_1 = require("ethers");
|
|
7
|
-
/**
|
|
8
|
-
* Function to manage Elliptic-curve cryptography
|
|
9
|
-
*/
|
|
10
|
-
exports.default = {
|
|
11
|
-
decrypt,
|
|
12
|
-
encrypt,
|
|
13
|
-
getAddressFromPrivateKey,
|
|
14
|
-
getAddressFromPublicKey,
|
|
15
|
-
recover,
|
|
16
|
-
sign,
|
|
17
|
-
};
|
|
18
8
|
/**
|
|
19
9
|
* Function to derive the address from an EC private key
|
|
20
10
|
*
|
|
@@ -38,6 +28,7 @@ function getAddressFromPrivateKey(privateKey) {
|
|
|
38
28
|
throw e;
|
|
39
29
|
}
|
|
40
30
|
}
|
|
31
|
+
exports.getAddressFromPrivateKey = getAddressFromPrivateKey;
|
|
41
32
|
/**
|
|
42
33
|
* Function to derive the address from an EC public key
|
|
43
34
|
*
|
|
@@ -58,14 +49,15 @@ function getAddressFromPublicKey(publicKey) {
|
|
|
58
49
|
throw e;
|
|
59
50
|
}
|
|
60
51
|
}
|
|
52
|
+
exports.getAddressFromPublicKey = getAddressFromPublicKey;
|
|
61
53
|
/**
|
|
62
|
-
* Function
|
|
54
|
+
* Function ecSigndata with ECDSA
|
|
63
55
|
*
|
|
64
56
|
* @param data the data to sign
|
|
65
57
|
*
|
|
66
58
|
* @returns the signature
|
|
67
59
|
*/
|
|
68
|
-
function
|
|
60
|
+
function ecSign(privateKey, data) {
|
|
69
61
|
try {
|
|
70
62
|
const signingKey = new ethers_1.ethers.utils.SigningKey(privateKey);
|
|
71
63
|
return ethers_1.ethers.utils.joinSignature(signingKey.signDigest(data));
|
|
@@ -79,6 +71,7 @@ function sign(privateKey, data) {
|
|
|
79
71
|
throw e;
|
|
80
72
|
}
|
|
81
73
|
}
|
|
74
|
+
exports.ecSign = ecSign;
|
|
82
75
|
/**
|
|
83
76
|
* Function to recover address from a signature
|
|
84
77
|
*
|
|
@@ -87,7 +80,7 @@ function sign(privateKey, data) {
|
|
|
87
80
|
*
|
|
88
81
|
* @returns the address
|
|
89
82
|
*/
|
|
90
|
-
function
|
|
83
|
+
function ecRecover(signature, data) {
|
|
91
84
|
try {
|
|
92
85
|
signature = signature.replace(/^0x/, '');
|
|
93
86
|
data = data.replace(/^0x/, '');
|
|
@@ -106,6 +99,7 @@ function recover(signature, data) {
|
|
|
106
99
|
throw e;
|
|
107
100
|
}
|
|
108
101
|
}
|
|
102
|
+
exports.ecRecover = ecRecover;
|
|
109
103
|
/**
|
|
110
104
|
* Function to encrypt data with a public key
|
|
111
105
|
*
|
|
@@ -114,10 +108,10 @@ function recover(signature, data) {
|
|
|
114
108
|
*
|
|
115
109
|
* @returns the encrypted data
|
|
116
110
|
*/
|
|
117
|
-
function
|
|
111
|
+
function ecEncrypt(publicKey, data) {
|
|
118
112
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
119
113
|
try {
|
|
120
|
-
//
|
|
114
|
+
// encrypts the data with the publicKey, returns the encrypted data with encryption parameters (such as IV..)
|
|
121
115
|
const compressed = compressPublicKey(publicKey);
|
|
122
116
|
const encrypted = yield EcCrypto.encrypt(Buffer.from(compressed), Buffer.from(data));
|
|
123
117
|
// Transforms the object with the encrypted data into a smaller string-representation.
|
|
@@ -137,6 +131,7 @@ function encrypt(publicKey, data) {
|
|
|
137
131
|
}
|
|
138
132
|
});
|
|
139
133
|
}
|
|
134
|
+
exports.ecEncrypt = ecEncrypt;
|
|
140
135
|
/**
|
|
141
136
|
* Function to decrypt data with a public key
|
|
142
137
|
*
|
|
@@ -145,10 +140,10 @@ function encrypt(publicKey, data) {
|
|
|
145
140
|
*
|
|
146
141
|
* @returns the decrypted data
|
|
147
142
|
*/
|
|
148
|
-
function
|
|
143
|
+
function ecDecrypt(privateKey, data) {
|
|
149
144
|
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
150
145
|
try {
|
|
151
|
-
const buf = yield EcCrypto.decrypt(Buffer.from(privateKey.replace(/^0x/, ''), 'hex'), eciesSplit(
|
|
146
|
+
const buf = yield EcCrypto.decrypt(Buffer.from(privateKey.replace(/^0x/, ''), 'hex'), eciesSplit(data));
|
|
152
147
|
return buf.toString();
|
|
153
148
|
}
|
|
154
149
|
catch (e) {
|
|
@@ -167,6 +162,7 @@ function decrypt(privateKey, encrypted) {
|
|
|
167
162
|
}
|
|
168
163
|
});
|
|
169
164
|
}
|
|
165
|
+
exports.ecDecrypt = ecDecrypt;
|
|
170
166
|
/**
|
|
171
167
|
* Converts a public key to its compressed form.
|
|
172
168
|
*/
|
|
@@ -180,7 +176,7 @@ function compressPublicKey(publicKey) {
|
|
|
180
176
|
}
|
|
181
177
|
/**
|
|
182
178
|
* Split an encrypted string to ECIES params
|
|
183
|
-
* inspired from https://github.com/pubkey/eth-crypto/blob/master/src/
|
|
179
|
+
* inspired from https://github.com/pubkey/eth-crypto/blob/master/src/ecDecrypt-with-private-key.js
|
|
184
180
|
*/
|
|
185
181
|
const eciesSplit = (str) => {
|
|
186
182
|
const buf = Buffer.from(str, 'hex');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ec-utils.js","sourceRoot":"","sources":["../../src/crypto/ec-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ec-utils.js","sourceRoot":"","sources":["../../src/crypto/ec-utils.ts"],"names":[],"mappings":";;;;AAAA,qCAAqC;AACrC,yCAA2D;AAC3D,mCAAgC;AAahC;;;;;;GAMG;AACH,SAAS,wBAAwB,CAAC,UAAkB;IAClD,IAAI;QACF,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YAC5B,UAAU,GAAG,IAAI,GAAG,UAAU,CAAC;SAChC;QACD,OAAO,eAAM,CAAC,KAAK,CAAC,cAAc,CAAC,eAAM,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;KACtE;IAAC,OAAO,CAAC,EAAE;QACV,IACE,CAAC,CAAC,OAAO,KAAK,+BAA+B;YAC7C,CAAC,CAAC,OAAO,KAAK,yDAAyD;YACvE,CAAC,CAAC,IAAI,KAAK,kBAAkB,EAC7B;YACA,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;SAC3E;QACD,MAAM,CAAC,CAAC;KACT;AACH,CAAC;AA7BC,4DAAwB;AA+B1B;;;;;;GAMG;AACH,SAAS,uBAAuB,CAAC,SAAiB;IAChD,IAAI;QACF,OAAO,eAAM,CAAC,KAAK,CAAC,cAAc,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC;KAClE;IAAC,OAAO,CAAC,EAAE;QACV,IACE,CAAC,CAAC,OAAO,KAAK,8BAA8B;YAC5C,CAAC,CAAC,OAAO,KAAK,8DAA8D;YAC5E,CAAC,CAAC,IAAI,KAAK,kBAAkB,EAC7B;YACA,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;SAC1E;QACD,MAAM,CAAC,CAAC;KACT;AACH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AiB,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAEtD,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC;QAClD,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC;QACpD,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC;QACnE,cAAc,EAAE,MAAM,CAAC,IAAI,CACzB,IAAA,4BAAgB,EAAC,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAC/E;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/crypto.d.ts
CHANGED
|
@@ -1,34 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { MultiFormatTypes } from '@requestnetwork/types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
decryptWithAes256cbc: (encryptedAndIv: Buffer, key: Buffer) => Promise<Buffer>;
|
|
6
|
-
decryptWithAes256gcm: (encryptedAndIv: Buffer, key: Buffer) => Promise<Buffer>;
|
|
7
|
-
encryptWithAes256cbc: (data: Buffer, key: Buffer) => Promise<Buffer>;
|
|
8
|
-
encryptWithAes256gcm: (data: Buffer, key: Buffer) => Promise<Buffer>;
|
|
9
|
-
random32Bytes: () => Promise<Buffer>;
|
|
10
|
-
};
|
|
11
|
-
EcUtils: {
|
|
12
|
-
decrypt: (privateKey: string, encrypted: string) => Promise<string>; /**
|
|
13
|
-
* manages crypto functions
|
|
14
|
-
*/
|
|
15
|
-
encrypt: (publicKey: string, data: string) => Promise<string>;
|
|
16
|
-
getAddressFromPrivateKey: (privateKey: string) => string;
|
|
17
|
-
getAddressFromPublicKey: (publicKey: string) => string;
|
|
18
|
-
recover: (signature: string, data: string) => string;
|
|
19
|
-
sign: (privateKey: string, data: string) => string;
|
|
20
|
-
};
|
|
21
|
-
generate32BufferKey: typeof generate32BufferKey;
|
|
22
|
-
generate8randomBytes: typeof generate8randomBytes;
|
|
23
|
-
keccak256Hash: typeof keccak256Hash;
|
|
24
|
-
last20bytesOfNormalizedKeccak256Hash: typeof last20bytesOfNormalizedKeccak256Hash;
|
|
25
|
-
normalize: typeof normalize;
|
|
26
|
-
normalizeKeccak256Hash: typeof normalizeKeccak256Hash;
|
|
27
|
-
};
|
|
2
|
+
import { decryptWithAes256cbc, decryptWithAes256gcm, encryptWithAes256cbc, encryptWithAes256gcm, random32Bytes } from './crypto/crypto-wrapper';
|
|
3
|
+
import { ecDecrypt, ecEncrypt, getAddressFromPrivateKey, getAddressFromPublicKey, ecRecover, ecSign } from './crypto/ec-utils';
|
|
28
4
|
/**
|
|
29
5
|
* manages crypto functions
|
|
30
6
|
*/
|
|
31
|
-
export
|
|
7
|
+
export { decryptWithAes256cbc, decryptWithAes256gcm, encryptWithAes256cbc, encryptWithAes256gcm, random32Bytes, ecDecrypt, ecEncrypt, getAddressFromPrivateKey, getAddressFromPublicKey, ecRecover, ecSign, generate32BufferKey, generate8randomBytes, keccak256Hash, last20bytesOfNormalizedKeccak256Hash, normalize, normalizeKeccak256Hash, };
|
|
32
8
|
/**
|
|
33
9
|
* Hashes with the keccak256 algorithm with a normalization before and formats it
|
|
34
10
|
*
|
package/dist/crypto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,SAAS,EACT,SAAS,EACT,wBAAwB,EACxB,uBAAuB,EACvB,SAAS,EACT,MAAM,EACP,MAAM,mBAAmB,CAAC;AAG3B;;GAEG;AACH,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,CAAC;AAEF;;;;;;;GAOG;AACH,iBAAS,sBAAsB,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAAC,SAAS,CAAC,KAAK,CAK/E;AAED;;;;;GAKG;AACH,iBAAS,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAUxC;AAED;;;;;GAKG;AACH,iBAAS,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;;;GAOG;AACH,iBAAS,oCAAoC,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAInE;AAED;;;;GAIG;AACH,iBAAe,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAEpD;AAED;;;;;;GAMG;AACH,iBAAe,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAGrD"}
|