react-native-quick-crypto 1.0.0-beta.11 → 1.0.0-beta.13
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/android/CMakeLists.txt +4 -0
- package/cpp/ed25519/HybridEdKeyPair.cpp +32 -89
- package/cpp/ed25519/HybridEdKeyPair.hpp +24 -54
- package/cpp/hash/HybridHash.cpp +151 -0
- package/cpp/hash/HybridHash.hpp +41 -0
- package/cpp/hmac/HybridHmac.cpp +95 -0
- package/cpp/hmac/HybridHmac.hpp +31 -0
- package/cpp/pbkdf2/HybridPbkdf2.cpp +34 -55
- package/cpp/pbkdf2/HybridPbkdf2.hpp +5 -16
- package/cpp/random/HybridRandom.cpp +5 -16
- package/cpp/random/HybridRandom.hpp +5 -6
- package/cpp/utils/Utils.hpp +1 -2
- package/lib/commonjs/hash.js +168 -0
- package/lib/commonjs/hash.js.map +1 -0
- package/lib/commonjs/hmac.js +109 -0
- package/lib/commonjs/hmac.js.map +1 -0
- package/lib/commonjs/index.js +26 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/hash.nitro.js +6 -0
- package/lib/commonjs/specs/hash.nitro.js.map +1 -0
- package/lib/commonjs/specs/hmac.nitro.js +6 -0
- package/lib/commonjs/specs/hmac.nitro.js.map +1 -0
- package/lib/module/hash.js +162 -0
- package/lib/module/hash.js.map +1 -0
- package/lib/module/hmac.js +104 -0
- package/lib/module/hmac.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/hash.nitro.js +4 -0
- package/lib/module/specs/hash.nitro.js.map +1 -0
- package/lib/module/specs/hmac.nitro.js +4 -0
- package/lib/module/specs/hmac.nitro.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/hash.d.ts +110 -0
- package/lib/typescript/hash.d.ts.map +1 -0
- package/lib/typescript/hmac.d.ts +67 -0
- package/lib/typescript/hmac.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/hash.nitro.d.ts +12 -0
- package/lib/typescript/specs/hash.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/hmac.nitro.d.ts +10 -0
- package/lib/typescript/specs/hmac.nitro.d.ts.map +1 -0
- package/lib/typescript/utils/types.d.ts +4 -0
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +2 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +20 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +20 -0
- package/nitrogen/generated/shared/c++/HybridHashSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridHashSpec.hpp +74 -0
- package/nitrogen/generated/shared/c++/HybridHmacSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridHmacSpec.hpp +66 -0
- package/package.json +1 -1
- package/src/hash.ts +208 -0
- package/src/hmac.ts +135 -0
- package/src/index.ts +6 -0
- package/src/specs/hash.nitro.ts +9 -0
- package/src/specs/hmac.nitro.ts +7 -0
- package/src/utils/types.ts +9 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Stream } from 'readable-stream';
|
|
4
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
5
|
+
import { ab2str, binaryLikeToArrayBuffer } from './utils';
|
|
6
|
+
class HashUtils {
|
|
7
|
+
static native = NitroModules.createHybridObject('Hash');
|
|
8
|
+
static getSupportedHashAlgorithms() {
|
|
9
|
+
return this.native.getSupportedHashAlgorithms();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function getHashes() {
|
|
13
|
+
return HashUtils.getSupportedHashAlgorithms();
|
|
14
|
+
}
|
|
15
|
+
class Hash extends Stream.Transform {
|
|
16
|
+
validate(args) {
|
|
17
|
+
if (typeof args.algorithm !== 'string' || args.algorithm.length === 0) throw new Error('Algorithm must be a non-empty string');
|
|
18
|
+
if (args.options?.outputLength !== undefined && args.options.outputLength < 0) throw new Error('Output length must be a non-negative number');
|
|
19
|
+
if (args.options?.outputLength !== undefined && typeof args.options.outputLength !== 'number') throw new Error('Output length must be a number');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @internal use `createHash()` instead
|
|
24
|
+
*/
|
|
25
|
+
constructor(args) {
|
|
26
|
+
super(args.options);
|
|
27
|
+
this.validate(args);
|
|
28
|
+
this.algorithm = args.algorithm;
|
|
29
|
+
this.options = args.options ?? {};
|
|
30
|
+
if (args.native) {
|
|
31
|
+
this.native = args.native;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.native = NitroModules.createHybridObject('Hash');
|
|
35
|
+
this.native.createHash(this.algorithm, this.options.outputLength);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Updates the hash content with the given `data`, the encoding of which
|
|
40
|
+
* is given in `inputEncoding`.
|
|
41
|
+
* If `encoding` is not provided, and the `data` is a string, an
|
|
42
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
43
|
+
*
|
|
44
|
+
* This can be called many times with new data as it is streamed.
|
|
45
|
+
* @since v1.0.0
|
|
46
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
update(data, inputEncoding) {
|
|
50
|
+
const defaultEncoding = 'utf8';
|
|
51
|
+
inputEncoding = inputEncoding ?? defaultEncoding;
|
|
52
|
+
this.native.update(binaryLikeToArrayBuffer(data, inputEncoding));
|
|
53
|
+
return this; // to support chaining syntax createHash().update().digest()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method).
|
|
58
|
+
* If `encoding` is provided a string will be returned; otherwise
|
|
59
|
+
* a `Buffer` is returned.
|
|
60
|
+
*
|
|
61
|
+
* The `Hash` object can not be used again after `hash.digest()` method has been
|
|
62
|
+
* called. Multiple calls will cause an error to be thrown.
|
|
63
|
+
* @since v1.0.0
|
|
64
|
+
* @param encoding The `encoding` of the return value.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
digest(encoding) {
|
|
68
|
+
const nativeDigest = this.native.digest(encoding);
|
|
69
|
+
if (encoding && encoding !== 'buffer') {
|
|
70
|
+
return ab2str(nativeDigest, encoding);
|
|
71
|
+
}
|
|
72
|
+
return Buffer.from(nativeDigest);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new `Hash` object that contains a deep copy of the internal state
|
|
77
|
+
* of the current `Hash` object.
|
|
78
|
+
*
|
|
79
|
+
* The optional `options` argument controls stream behavior. For XOF hash
|
|
80
|
+
* functions such as `'shake256'`, the `outputLength` option can be used to
|
|
81
|
+
* specify the desired output length in bytes.
|
|
82
|
+
*
|
|
83
|
+
* An error is thrown when an attempt is made to copy the `Hash` object after
|
|
84
|
+
* its `hash.digest()` method has been called.
|
|
85
|
+
*
|
|
86
|
+
* ```js
|
|
87
|
+
* // Calculate a rolling hash.
|
|
88
|
+
* import { createHash } from 'react-native-quick-crypto';
|
|
89
|
+
*
|
|
90
|
+
* const hash = createHash('sha256');
|
|
91
|
+
*
|
|
92
|
+
* hash.update('one');
|
|
93
|
+
* console.log(hash.copy().digest('hex'));
|
|
94
|
+
*
|
|
95
|
+
* hash.update('two');
|
|
96
|
+
* console.log(hash.copy().digest('hex'));
|
|
97
|
+
*
|
|
98
|
+
* hash.update('three');
|
|
99
|
+
* console.log(hash.copy().digest('hex'));
|
|
100
|
+
*
|
|
101
|
+
* // Etc.
|
|
102
|
+
* ```
|
|
103
|
+
* @since v1.0.0
|
|
104
|
+
* @param options `stream.transform` options
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
copy(options) {
|
|
108
|
+
const newOptions = options ?? this.options;
|
|
109
|
+
const newNativeHash = this.native.copy(newOptions.outputLength);
|
|
110
|
+
const hash = new Hash({
|
|
111
|
+
algorithm: this.algorithm,
|
|
112
|
+
options: newOptions,
|
|
113
|
+
native: newNativeHash
|
|
114
|
+
});
|
|
115
|
+
return hash;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// stream interface
|
|
119
|
+
_transform(chunk, encoding, callback) {
|
|
120
|
+
this.update(chunk, encoding);
|
|
121
|
+
callback();
|
|
122
|
+
}
|
|
123
|
+
_flush(callback) {
|
|
124
|
+
this.push(this.digest());
|
|
125
|
+
callback();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Creates and returns a `Hash` object that can be used to generate hash digests
|
|
131
|
+
* using the given `algorithm`. Optional `options` argument controls stream
|
|
132
|
+
* behavior. For XOF hash functions such as `'shake256'`, the `outputLength` option
|
|
133
|
+
* can be used to specify the desired output length in bytes.
|
|
134
|
+
*
|
|
135
|
+
* The `algorithm` is dependent on the available algorithms supported by the
|
|
136
|
+
* version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
|
|
137
|
+
* On recent releases of OpenSSL, `openssl list -digest-algorithms` will
|
|
138
|
+
* display the available digest algorithms.
|
|
139
|
+
*
|
|
140
|
+
* Example: generating the sha256 sum of a file
|
|
141
|
+
*
|
|
142
|
+
* ```js
|
|
143
|
+
* import crypto from 'react-native-quick-crypto';
|
|
144
|
+
*
|
|
145
|
+
* const hash = crypto.createHash('sha256').update('Test123').digest('hex');
|
|
146
|
+
* console.log('SHA-256 of "Test123":', hash);
|
|
147
|
+
* ```
|
|
148
|
+
* @since v1.0.0
|
|
149
|
+
* @param options `stream.transform` options
|
|
150
|
+
*/
|
|
151
|
+
export function createHash(algorithm, options) {
|
|
152
|
+
// @ts-expect-error private constructor
|
|
153
|
+
return new Hash({
|
|
154
|
+
algorithm,
|
|
155
|
+
options
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
export const hashExports = {
|
|
159
|
+
createHash,
|
|
160
|
+
getHashes
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Stream","NitroModules","ab2str","binaryLikeToArrayBuffer","HashUtils","native","createHybridObject","getSupportedHashAlgorithms","getHashes","Hash","Transform","validate","args","algorithm","length","Error","options","outputLength","undefined","constructor","createHash","update","data","inputEncoding","defaultEncoding","digest","encoding","nativeDigest","Buffer","from","copy","newOptions","newNativeHash","hash","_transform","chunk","callback","_flush","push","hashExports"],"sourceRoot":"../../src","sources":["hash.ts"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,iBAAiB;AACxC,SAASC,YAAY,QAAQ,4BAA4B;AAIzD,SAASC,MAAM,EAAEC,uBAAuB,QAAQ,SAAS;AAEzD,MAAMC,SAAS,CAAC;EACd,OAAeC,MAAM,GAAGJ,YAAY,CAACK,kBAAkB,CAAa,MAAM,CAAC;EAC3E,OAAcC,0BAA0BA,CAAA,EAAa;IACnD,OAAO,IAAI,CAACF,MAAM,CAACE,0BAA0B,CAAC,CAAC;EACjD;AACF;AAEA,OAAO,SAASC,SAASA,CAAA,EAAG;EAC1B,OAAOJ,SAAS,CAACG,0BAA0B,CAAC,CAAC;AAC/C;AAgBA,MAAME,IAAI,SAAST,MAAM,CAACU,SAAS,CAAC;EAK1BC,QAAQA,CAACC,IAAc,EAAE;IAC/B,IAAI,OAAOA,IAAI,CAACC,SAAS,KAAK,QAAQ,IAAID,IAAI,CAACC,SAAS,CAACC,MAAM,KAAK,CAAC,EACnE,MAAM,IAAIC,KAAK,CAAC,sCAAsC,CAAC;IACzD,IACEH,IAAI,CAACI,OAAO,EAAEC,YAAY,KAAKC,SAAS,IACxCN,IAAI,CAACI,OAAO,CAACC,YAAY,GAAG,CAAC,EAE7B,MAAM,IAAIF,KAAK,CAAC,6CAA6C,CAAC;IAChE,IACEH,IAAI,CAACI,OA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
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Buffer } from '@craftzdog/react-native-buffer';
|
|
4
|
+
import { Stream } from 'readable-stream';
|
|
5
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
6
|
+
import { ab2str, binaryLikeToArrayBuffer } from './utils/conversion';
|
|
7
|
+
class Hmac extends Stream.Transform {
|
|
8
|
+
validate(args) {
|
|
9
|
+
if (typeof args.algorithm !== 'string' || args.algorithm.length === 0) throw new Error('Algorithm must be a non-empty string');
|
|
10
|
+
if (args.key === null || args.key === undefined) throw new Error('Key must not be null or undefined');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @internal use `createHmac()` instead
|
|
15
|
+
*/
|
|
16
|
+
constructor(args) {
|
|
17
|
+
super(args.options);
|
|
18
|
+
this.validate(args);
|
|
19
|
+
this.algorithm = args.algorithm;
|
|
20
|
+
this.key = args.key;
|
|
21
|
+
this.native = NitroModules.createHybridObject('Hmac');
|
|
22
|
+
this.native.createHmac(this.algorithm, binaryLikeToArrayBuffer(this.key));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Updates the `Hmac` content with the given `data`, the encoding of which is given in `inputEncoding`.
|
|
27
|
+
* If `encoding` is not provided, and the `data` is a string, an encoding of `'utf8'` is enforced.
|
|
28
|
+
* If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
29
|
+
*
|
|
30
|
+
* This can be called many times with new data as it is streamed.
|
|
31
|
+
* @since v1.0.0
|
|
32
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
update(data, inputEncoding) {
|
|
36
|
+
const defaultEncoding = 'utf8';
|
|
37
|
+
inputEncoding = inputEncoding ?? defaultEncoding;
|
|
38
|
+
this.native.update(binaryLikeToArrayBuffer(data, inputEncoding));
|
|
39
|
+
return this; // to support chaining syntax createHmac().update().digest()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Calculates the HMAC digest of all of the data passed using `hmac.update()`.
|
|
44
|
+
* If `encoding` is provided a string is returned; otherwise a `Buffer` is returned;
|
|
45
|
+
*
|
|
46
|
+
* The `Hmac` object can not be used again after `hmac.digest()` has been
|
|
47
|
+
* called. Multiple calls to `hmac.digest()` will result in an error being thrown.
|
|
48
|
+
* @since v1.0.0
|
|
49
|
+
* @param encoding The `encoding` of the return value.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
digest(encoding) {
|
|
53
|
+
const nativeDigest = this.native.digest();
|
|
54
|
+
if (encoding && encoding !== 'buffer') {
|
|
55
|
+
return ab2str(nativeDigest, encoding);
|
|
56
|
+
}
|
|
57
|
+
return Buffer.from(nativeDigest);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// stream interface
|
|
61
|
+
_transform(chunk, encoding, callback) {
|
|
62
|
+
this.update(chunk, encoding);
|
|
63
|
+
callback();
|
|
64
|
+
}
|
|
65
|
+
_flush(callback) {
|
|
66
|
+
this.push(this.digest());
|
|
67
|
+
callback();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Creates and returns an `Hmac` object that uses the given `algorithm` and `key`.
|
|
73
|
+
* Optional `options` argument controls stream behavior.
|
|
74
|
+
*
|
|
75
|
+
* The `algorithm` is dependent on the available algorithms supported by the
|
|
76
|
+
* version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
|
|
77
|
+
* On recent releases of OpenSSL, `openssl list -digest-algorithms` will
|
|
78
|
+
* display the available digest algorithms.
|
|
79
|
+
*
|
|
80
|
+
* Example: generating the sha256 HMAC of a file
|
|
81
|
+
*
|
|
82
|
+
* ```js
|
|
83
|
+
* import crypto from 'react-native-quick-crypto';
|
|
84
|
+
*
|
|
85
|
+
* const hmac = crypto.createHmac('sha256', 'secret-key');
|
|
86
|
+
* hmac.update('message to hash');
|
|
87
|
+
* const digest = hmac.digest('hex');
|
|
88
|
+
* console.log(digest); // prints HMAC digest in hexadecimal format
|
|
89
|
+
* ```
|
|
90
|
+
* @since v1.0.0
|
|
91
|
+
* @param options `stream.transform` options
|
|
92
|
+
*/
|
|
93
|
+
export function createHmac(algorithm, key, options) {
|
|
94
|
+
// @ts-expect-error private constructor
|
|
95
|
+
return new Hmac({
|
|
96
|
+
algorithm,
|
|
97
|
+
key,
|
|
98
|
+
options
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
export const hmacExports = {
|
|
102
|
+
createHmac
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=hmac.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Buffer","Stream","NitroModules","ab2str","binaryLikeToArrayBuffer","Hmac","Transform","validate","args","algorithm","length","Error","key","undefined","constructor","options","native","createHybridObject","createHmac","update","data","inputEncoding","defaultEncoding","digest","encoding","nativeDigest","from","_transform","chunk","callback","_flush","push","hmacExports"],"sourceRoot":"../../src","sources":["hmac.ts"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,gCAAgC;AACvD,SAASC,MAAM,QAAQ,iBAAiB;AACxC,SAASC,YAAY,QAAQ,4BAA4B;AAIzD,SAASC,MAAM,EAAEC,uBAAuB,QAAQ,oBAAoB;AAQpE,MAAMC,IAAI,SAASJ,MAAM,CAACK,SAAS,CAAC;EAK1BC,QAAQA,CAACC,IAAc,EAAE;IAC/B,IAAI,OAAOA,IAAI,CAACC,SAAS,KAAK,QAAQ,IAAID,IAAI,CAACC,SAAS,CAACC,MAAM,KAAK,CAAC,EACnE,MAAM,IAAIC,KAAK,CAAC,sCAAsC,CAAC;IACzD,IAAIH,IAAI,CAACI,GAAG,KAAK,IAAI,IAAIJ,IAAI,CAACI,GAAG,KAAKC,SAAS,EAC7C,MAAM,IAAIF,KAAK,CAAC,mCAAmC,CAAC;EACxD;;EAEA;AACF;AACA;EACUG,WAAWA,CAACN,IAAc,EAAE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R,MAAM,CAAC,CAAC,CAAC;IACxBM,QAAQ,CAAC,CAAC;EACZ;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASX,UAAUA,CACxBT,SAAiB,EACjBG,GAAe,EACfG,OAA0B,EACpB;EACN;EACA,OAAO,IAAIV,IAAI,CAAC;IACdI,SAAS;IACTG,GAAG;IACHG;EACF,CAAC,CAAC;AACJ;AAEA,OAAO,MAAMiB,WAAW,GAAG;EACzBd;AACF,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -5,6 +5,8 @@ import { Buffer } from '@craftzdog/react-native-buffer';
|
|
|
5
5
|
|
|
6
6
|
// API imports
|
|
7
7
|
import * as keys from './keys';
|
|
8
|
+
import { hashExports as hash } from './hash';
|
|
9
|
+
import { hmacExports as hmac } from './hmac';
|
|
8
10
|
import * as ed from './ed';
|
|
9
11
|
import * as pbkdf2 from './pbkdf2';
|
|
10
12
|
import * as random from './random';
|
|
@@ -35,6 +37,8 @@ const QuickCrypto = {
|
|
|
35
37
|
// subtle,
|
|
36
38
|
// constants,
|
|
37
39
|
...keys,
|
|
40
|
+
...hash,
|
|
41
|
+
...hmac,
|
|
38
42
|
...ed,
|
|
39
43
|
...pbkdf2,
|
|
40
44
|
...random,
|
|
@@ -61,6 +65,8 @@ global.process.nextTick = setImmediate;
|
|
|
61
65
|
|
|
62
66
|
// exports
|
|
63
67
|
export default QuickCrypto;
|
|
68
|
+
export * from './hash';
|
|
69
|
+
export * from './hmac';
|
|
64
70
|
export * from './ed';
|
|
65
71
|
export * from './pbkdf2';
|
|
66
72
|
export * from './random';
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Buffer","keys","ed","pbkdf2","random","utils","QuickCrypto","install","global","crypto","process","nextTick","setImmediate","module","exports","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA,SAASA,MAAM,QAAQ,gCAAgC;;AAEvD;AACA,OAAO,KAAKC,IAAI,MAAM,QAAQ;AAC9B,OAAO,KAAKC,EAAE,MAAM,MAAM;AAC1B,OAAO,KAAKC,MAAM,MAAM,UAAU;AAClC,OAAO,KAAKC,MAAM,MAAM,UAAU;;AAElC;AACA,OAAO,KAAKC,KAAK,MAAM,SAAS;;AAEhC;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAG;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,
|
|
1
|
+
{"version":3,"names":["Buffer","keys","hashExports","hash","hmacExports","hmac","ed","pbkdf2","random","utils","QuickCrypto","install","global","crypto","process","nextTick","setImmediate","module","exports","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA,SAASA,MAAM,QAAQ,gCAAgC;;AAEvD;AACA,OAAO,KAAKC,IAAI,MAAM,QAAQ;AAC9B,SAASC,WAAW,IAAIC,IAAI,QAAQ,QAAQ;AAC5C,SAASC,WAAW,IAAIC,IAAI,QAAQ,QAAQ;AAC5C,OAAO,KAAKC,EAAE,MAAM,MAAM;AAC1B,OAAO,KAAKC,MAAM,MAAM,UAAU;AAClC,OAAO,KAAKC,MAAM,MAAM,UAAU;;AAElC;AACA,OAAO,KAAKC,KAAK,MAAM,SAAS;;AAEhC;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAG;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,GAAGT,IAAI;EACP,GAAGE,IAAI;EACP,GAAGE,IAAI;EACP,GAAGC,EAAE;EACL,GAAGC,MAAM;EACT,GAAGC,MAAM;EACT;EACA;EACA;EACA,GAAGC;AACL,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAME,OAAO,GAAGA,CAAA,KAAM;EAC3B;EACAC,MAAM,CAACZ,MAAM,GAAGA,MAAM;;EAEtB;EACAY,MAAM,CAACC,MAAM,GAAGH,WAAW;AAC7B,CAAC;;AAED;AACAE,MAAM,CAACE,OAAO,CAACC,QAAQ,GAAGC,YAAY;;AAEtC;AACA,eAAeN,WAAW;AAC1B,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB,cAAc,MAAM;AACpB,cAAc,UAAU;AACxB,cAAc,UAAU;AACxB,cAAc,SAAS;;AAEvB;AACAO,MAAM,CAACC,OAAO,GAAGR,WAAW;AAC5BO,MAAM,CAACC,OAAO,CAACC,OAAO,GAAGT,WAAW;AACpCO,MAAM,CAACC,OAAO,CAACP,OAAO,GAAGA,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/hash.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/hmac.nitro.ts"],"mappings":"","ignoreList":[]}
|