@dxos/crypto 0.0.1 → 0.1.0
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/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/src/browser/subtle.d.ts +2 -0
- package/dist/src/browser/subtle.d.ts.map +1 -0
- package/dist/src/browser/subtle.js +9 -0
- package/dist/src/browser/subtle.js.map +1 -0
- package/dist/src/encrypt.d.ts +17 -0
- package/dist/src/encrypt.d.ts.map +1 -0
- package/dist/src/encrypt.js +40 -0
- package/dist/src/encrypt.js.map +1 -0
- package/dist/src/encrypt.test.d.ts +2 -0
- package/dist/src/encrypt.test.d.ts.map +1 -0
- package/dist/src/encrypt.test.js +45 -0
- package/dist/src/encrypt.test.js.map +1 -0
- package/dist/src/hash.d.ts +21 -0
- package/dist/src/hash.d.ts.map +1 -0
- package/dist/src/hash.js +46 -0
- package/dist/src/hash.js.map +1 -0
- package/dist/src/hash.test.d.ts +2 -0
- package/dist/src/hash.test.d.ts.map +1 -0
- package/dist/src/hash.test.js +26 -0
- package/dist/src/hash.test.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +27 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/keys.d.ts +32 -0
- package/dist/src/keys.d.ts.map +1 -0
- package/dist/src/keys.js +70 -0
- package/dist/src/keys.js.map +1 -0
- package/dist/src/keys.test.d.ts +2 -0
- package/dist/src/keys.test.d.ts.map +1 -0
- package/dist/src/keys.test.js +11 -0
- package/dist/src/keys.test.js.map +1 -0
- package/dist/src/signer.d.ts +12 -0
- package/dist/src/signer.d.ts.map +1 -0
- package/dist/src/signer.js +6 -0
- package/dist/src/signer.js.map +1 -0
- package/dist/src/subtle.d.ts +4 -0
- package/dist/src/subtle.d.ts.map +1 -0
- package/dist/src/subtle.js +32 -0
- package/dist/src/subtle.js.map +1 -0
- package/dist/src/validator.d.ts +6 -0
- package/dist/src/validator.d.ts.map +1 -0
- package/dist/src/validator.js +15 -0
- package/dist/src/validator.js.map +1 -0
- package/dist/src/verify.d.ts +6 -0
- package/dist/src/verify.d.ts.map +1 -0
- package/dist/src/verify.js +28 -0
- package/dist/src/verify.js.map +1 -0
- package/package.json +30 -27
- package/src/browser/subtle.ts +7 -0
- package/src/{encrypt.test.js → encrypt.test.ts} +4 -6
- package/src/encrypt.ts +36 -0
- package/src/hash.test.ts +32 -0
- package/src/hash.ts +42 -0
- package/src/index.ts +11 -0
- package/src/keys.test.ts +11 -0
- package/src/keys.ts +71 -0
- package/src/signer.ts +16 -0
- package/src/subtle.ts +7 -0
- package/src/validator.ts +14 -0
- package/src/verify.ts +39 -0
- package/babel.config.js +0 -14
- package/dist/es/encrypt.js +0 -51
- package/dist/es/index.js +0 -42
- package/dist/es/keys.js +0 -125
- package/dist/es/validator.js +0 -27
- package/src/encrypt.js +0 -36
- package/src/index.js +0 -7
- package/src/keys.js +0 -98
- package/src/keys.test.js +0 -23
- package/src/validator.js +0 -14
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 DXOS.org
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Crypto
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.com/dxos/crypto)
|
|
4
|
+
[](https://coveralls.io/github/dxos/crypto?branch=master)
|
|
5
|
+
[](https://greenkeeper.io/)
|
|
6
|
+
[](https://github.com/standard/semistandard)
|
|
7
|
+
[](https://github.com/RichardLitt/standard-readme)
|
|
8
|
+
|
|
9
|
+
Low-level crypto utils.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subtle.d.ts","sourceRoot":"","sources":["../../../src/browser/subtle.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,cAAgB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.subtleCrypto = void 0;
|
|
7
|
+
// Replacement implementation for the browser (see package.json).
|
|
8
|
+
exports.subtleCrypto = crypto.subtle;
|
|
9
|
+
//# sourceMappingURL=subtle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subtle.js","sourceRoot":"","sources":["../../../src/browser/subtle.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAEF,iEAAiE;AAEpD,QAAA,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypt string plaintext to a base64-encoded string ciphertext.
|
|
3
|
+
* @param plaintext
|
|
4
|
+
* @param passphrase
|
|
5
|
+
* @param cipher see https://cryptojs.gitbook.io/docs/#ciphers
|
|
6
|
+
* @returns ciphertext
|
|
7
|
+
*/
|
|
8
|
+
export declare const encrypt: (plaintext: string, passphrase: string, cipher?: string) => any;
|
|
9
|
+
/**
|
|
10
|
+
* Decrypt from a base64-encoded string ciphertext to string plaintext.
|
|
11
|
+
* @param ciphertext
|
|
12
|
+
* @param passphrase
|
|
13
|
+
* @param cipher see https://cryptojs.gitbook.io/docs/#ciphers
|
|
14
|
+
* @returns plaintext
|
|
15
|
+
*/
|
|
16
|
+
export declare const decrypt: (ciphertext: string, passphrase: string, cipher?: string) => any;
|
|
17
|
+
//# sourceMappingURL=encrypt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../src/encrypt.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,cAAe,MAAM,cAAc,MAAM,yBAK5D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,eAAgB,MAAM,cAAc,MAAM,yBAO7D,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2020 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.decrypt = exports.encrypt = void 0;
|
|
10
|
+
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
11
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
12
|
+
/**
|
|
13
|
+
* Encrypt string plaintext to a base64-encoded string ciphertext.
|
|
14
|
+
* @param plaintext
|
|
15
|
+
* @param passphrase
|
|
16
|
+
* @param cipher see https://cryptojs.gitbook.io/docs/#ciphers
|
|
17
|
+
* @returns ciphertext
|
|
18
|
+
*/
|
|
19
|
+
const encrypt = (plaintext, passphrase, cipher = 'AES') => {
|
|
20
|
+
(0, node_assert_1.default)(typeof passphrase === 'string');
|
|
21
|
+
(0, node_assert_1.default)(typeof cipher === 'string');
|
|
22
|
+
return crypto_js_1.default[cipher].encrypt(plaintext, passphrase).toString();
|
|
23
|
+
};
|
|
24
|
+
exports.encrypt = encrypt;
|
|
25
|
+
/**
|
|
26
|
+
* Decrypt from a base64-encoded string ciphertext to string plaintext.
|
|
27
|
+
* @param ciphertext
|
|
28
|
+
* @param passphrase
|
|
29
|
+
* @param cipher see https://cryptojs.gitbook.io/docs/#ciphers
|
|
30
|
+
* @returns plaintext
|
|
31
|
+
*/
|
|
32
|
+
const decrypt = (ciphertext, passphrase, cipher = 'AES') => {
|
|
33
|
+
(0, node_assert_1.default)(typeof ciphertext === 'string');
|
|
34
|
+
(0, node_assert_1.default)(typeof passphrase === 'string');
|
|
35
|
+
(0, node_assert_1.default)(typeof cipher === 'string');
|
|
36
|
+
const bytes = crypto_js_1.default[cipher].decrypt(ciphertext, passphrase);
|
|
37
|
+
return bytes.toString(crypto_js_1.default.enc.Utf8);
|
|
38
|
+
};
|
|
39
|
+
exports.decrypt = decrypt;
|
|
40
|
+
//# sourceMappingURL=encrypt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../../src/encrypt.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,0DAAiC;AACjC,8DAAiC;AAEjC;;;;;;GAMG;AACI,MAAM,OAAO,GAAG,CAAC,SAAiB,EAAE,UAAkB,EAAE,MAAM,GAAG,KAAK,EAAE,EAAE;IAC/E,IAAA,qBAAM,EAAC,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC;IACvC,IAAA,qBAAM,EAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC;IAEnC,OAAQ,mBAAgB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC7E,CAAC,CAAC;AALW,QAAA,OAAO,WAKlB;AAEF;;;;;;GAMG;AACI,MAAM,OAAO,GAAG,CAAC,UAAkB,EAAE,UAAkB,EAAE,MAAM,GAAG,KAAK,EAAE,EAAE;IAChF,IAAA,qBAAM,EAAC,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC;IACvC,IAAA,qBAAM,EAAC,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC;IACvC,IAAA,qBAAM,EAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC;IAEnC,MAAM,KAAK,GAAI,mBAAgB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACxE,OAAO,KAAK,CAAC,QAAQ,CAAC,mBAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC3C,CAAC,CAAC;AAPW,QAAA,OAAO,WAOlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encrypt.test.d.ts","sourceRoot":"","sources":["../../src/encrypt.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2020 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chai_1 = require("chai");
|
|
7
|
+
const encrypt_1 = require("./encrypt");
|
|
8
|
+
// Using JSON test data due to its popularity. Any text should work.
|
|
9
|
+
const testJsonData = `{"keys":[{"added":"2020-02-04T22:22:37-07:00","created":"2020-02-04T22:22:37-07:00","hint":false,
|
|
10
|
+
"key":"9d902af1d1d6f42e2c6736cea4191b05368f1df77181bc8d798d8db946c48cd4","own":true,"publicKey":"9d902af1d1d6f42e2c6736
|
|
11
|
+
cea4191b05368f1df77181bc8d798d8db946c48cd4","secretKey":"1fb50514ae9edb4cadc448a60f345f69459616f3ad5e9d74d5a8c920b8b5f7
|
|
12
|
+
409d902af1d1d6f42e2c6736cea4191b05368f1df77181bc8d798d8db946c48cd4","trusted":true,"type":"IDENTITY"},{"added":"2020-02
|
|
13
|
+
-04T22:22:37-07:00","created":"2020-02-04T22:22:37-07:00","hint":false,"key":"1a9cd591afb12920546c2e35ebc341dd54f30c261
|
|
14
|
+
90118998596991f3fd1af5c","own":true,"publicKey":"1a9cd591afb12920546c2e35ebc341dd54f30c26190118998596991f3fd1af5c","sec
|
|
15
|
+
retKey":"51885b933a7fc50f7e8e94b34336497b1030d7e5b112ad6c7721bc1f34766a4a1a9cd591afb12920546c2e35ebc341dd54f30c26190118
|
|
16
|
+
998596991f3fd1af5c","trusted":true,"type":"PSEUDONYM"},{"added":"2020-02-04T22:22:37-07:00","created":"2020-02-04T22:22
|
|
17
|
+
:37-07:00","hint":false,"key":"6047e56f37dfd50a24590acb861dd5095955fedbd87d133f06b576146a3305ab","own":true,"publicKey"
|
|
18
|
+
:"6047e56f37dfd50a24590acb861dd5095955fedbd87d133f06b576146a3305ab","secretKey":"6737bec794cc8547dc5062afe70c01522b94c0
|
|
19
|
+
d945729ff8cf9e9669d09366436047e56f37dfd50a24590acb861dd5095955fedbd87d133f06b576146a3305ab","trusted":true,"type":"DEVI
|
|
20
|
+
CE"},{"added":"2020-02-04T22:22:37-07:00","created":"2020-02-04T22:22:37-07:00","hint":false,"key":"2dd57ada7744cf5db66
|
|
21
|
+
d8183505086e9b3e1853e7af79857e443299abe103b58","own":true,"publicKey":"2dd57ada7744cf5db66d8183505086e9b3e1853e7af79857
|
|
22
|
+
e443299abe103b58","secretKey":"4c5c53e97267bcf295bb91eaaf83d69b619a3df195ec085b4ca7e41cbf88f2e12dd57ada7744cf5db66d8183
|
|
23
|
+
505086e9b3e1853e7af79857e443299abe103b58","trusted":true,"type":"DEVICE_IDENTITY"},{"added":"2020-02-04T22:22:37-07:00"
|
|
24
|
+
,"created":"2020-02-04T22:22:37-07:00","hint":false,"key":"6fbe6aacfd25e7324b7420f3d38b93316eed6097d58d261f6f802d33903b
|
|
25
|
+
b7c9","own":true,"publicKey":"6fbe6aacfd25e7324b7420f3d38b93316eed6097d58d261f6f802d33903bb7c9","secretKey":"67aeedd8fc
|
|
26
|
+
d0555d455097daafc777103697f96e3697847d30ea802057d4795f6fbe6aacfd25e7324b7420f3d38b93316eed6097d58d261f6f802d33903bb7c9"
|
|
27
|
+
,"trusted":true,"type":"DEVICE_PSEUDONYM"},{"added":"2020-02-04T22:22:37-07:00","created":"2020-02-04T22:22:37-07:00","
|
|
28
|
+
hint":false,"key":"0d7a22f56bc1e398a5611f592d6a41fcc0f93cf233437d5f3a7f760de2b2bc75","own":true,"publicKey":"0d7a22f56b
|
|
29
|
+
c1e398a5611f592d6a41fcc0f93cf233437d5f3a7f760de2b2bc75","secretKey":"279e5ee1ec0b45d3505ab8a3fc79f1b2d9f71667ac311e36e4
|
|
30
|
+
d237bca84e68920d7a22f56bc1e398a5611f592d6a41fcc0f93cf233437d5f3a7f760de2b2bc75","trusted":true,"type":"PARTY"},{"added"
|
|
31
|
+
:"2020-02-04T22:22:37-07:00","created":"2020-02-04T22:22:37-07:00","hint":false,"key":"c8e865ae089f4cb5add830b67fa676dd
|
|
32
|
+
c0e813f5333272633b305b359115a6b6","own":true,"publicKey":"c8e865ae089f4cb5add830b67fa676ddc0e813f5333272633b305b359115a
|
|
33
|
+
6b6","secretKey":"1a211268f48fe9fc4d6a294b320bc1f92a592631d0bbdb5c94a8a8626a150a2dc8e865ae089f4cb5add830b67fa676ddc0e81
|
|
34
|
+
3f5333272633b305b359115a6b6","trusted":true,"type":"FEED"},{"added":"2020-02-04T22:22:37-07:00","created":"2020-02-04T2
|
|
35
|
+
2:22:37-07:00","hint":false,"key":"4f5e87626c62c5f61873d1e7c995c1b7e7e66e7600b454fa370a93d18f4a9a6f","own":true,"public
|
|
36
|
+
Key":"4f5e87626c62c5f61873d1e7c995c1b7e7e66e7600b454fa370a93d18f4a9a6f","secretKey":"94a4ce17823895e25fa637ce6aa9ef9bcd
|
|
37
|
+
8c13d81376b61fb252db32d1002bba4f5e87626c62c5f61873d1e7c995c1b7e7e66e7600b454fa370a93d18f4a9a6f","trusted":true,"type":"
|
|
38
|
+
UNKNOWN"}]}';`;
|
|
39
|
+
it('Bulk encryption/decryption', function () {
|
|
40
|
+
const original = testJsonData;
|
|
41
|
+
const origCrypt = (0, encrypt_1.encrypt)(original, 'secret12');
|
|
42
|
+
const copy = (0, encrypt_1.decrypt)(origCrypt, 'secret12');
|
|
43
|
+
(0, chai_1.expect)(original).to.equal(copy);
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=encrypt.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encrypt.test.js","sourceRoot":"","sources":["../../src/encrypt.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;AAEF,+BAA8B;AAE9B,uCAA6C;AAE7C,oEAAoE;AACpE,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6BP,CAAC;AAEf,EAAE,CAAC,4BAA4B,EAAE;IAC/B,MAAM,QAAQ,GAAG,YAAY,CAAC;IAE9B,MAAM,SAAS,GAAG,IAAA,iBAAO,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,IAAA,iBAAO,EAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAE5C,IAAA,aAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a SHA-1 hash of the supplied string, returned as a hexadecimal string.
|
|
3
|
+
* @param text
|
|
4
|
+
*/
|
|
5
|
+
export declare const sha1: (text: string) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a SHA-256 hash of the supplied string, returned as a hexadecimal string.
|
|
8
|
+
* @param text
|
|
9
|
+
*/
|
|
10
|
+
export declare const sha256: (text: string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a SHA-512 hash of the supplied string, returned as a hexadecimal string.
|
|
13
|
+
* @param text
|
|
14
|
+
*/
|
|
15
|
+
export declare const sha512: (text: string) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a SHA-512 hash of the supplied string, returned as a hexadecimal string.
|
|
18
|
+
* @param text
|
|
19
|
+
*/
|
|
20
|
+
export declare const ripemd160: (text: string) => string;
|
|
21
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,eAAO,MAAM,IAAI,SAAU,MAAM,WAAwB,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,MAAM,SAAU,MAAM,WAA0B,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,MAAM,SAAU,MAAM,WAA0B,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,SAAS,SAAU,MAAM,WAA6B,CAAC"}
|
package/dist/src/hash.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2020 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ripemd160 = exports.sha512 = exports.sha256 = exports.sha1 = void 0;
|
|
10
|
+
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
11
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param algorithm
|
|
15
|
+
* @param plaintext
|
|
16
|
+
*/
|
|
17
|
+
const _hash = (algorithm, plaintext) => {
|
|
18
|
+
(0, node_assert_1.default)(typeof algorithm === 'string');
|
|
19
|
+
(0, node_assert_1.default)(typeof plaintext === 'string');
|
|
20
|
+
return crypto_js_1.default[algorithm](plaintext).toString();
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Creates a SHA-1 hash of the supplied string, returned as a hexadecimal string.
|
|
24
|
+
* @param text
|
|
25
|
+
*/
|
|
26
|
+
const sha1 = (text) => _hash('SHA1', text);
|
|
27
|
+
exports.sha1 = sha1;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a SHA-256 hash of the supplied string, returned as a hexadecimal string.
|
|
30
|
+
* @param text
|
|
31
|
+
*/
|
|
32
|
+
const sha256 = (text) => _hash('SHA256', text);
|
|
33
|
+
exports.sha256 = sha256;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a SHA-512 hash of the supplied string, returned as a hexadecimal string.
|
|
36
|
+
* @param text
|
|
37
|
+
*/
|
|
38
|
+
const sha512 = (text) => _hash('SHA512', text);
|
|
39
|
+
exports.sha512 = sha512;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a SHA-512 hash of the supplied string, returned as a hexadecimal string.
|
|
42
|
+
* @param text
|
|
43
|
+
*/
|
|
44
|
+
const ripemd160 = (text) => _hash('RIPEMD160', text);
|
|
45
|
+
exports.ripemd160 = ripemd160;
|
|
46
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,0DAAiC;AACjC,8DAAiC;AAEjC;;;;GAIG;AACH,MAAM,KAAK,GAAG,CAAC,SAAiB,EAAE,SAAiB,EAAU,EAAE;IAC7D,IAAA,qBAAM,EAAC,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC;IACtC,IAAA,qBAAM,EAAC,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC;IAEtC,OAAQ,mBAAgB,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC5D,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAA7C,QAAA,IAAI,QAAyC;AAE1D;;;GAGG;AACI,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAAjD,QAAA,MAAM,UAA2C;AAE9D;;;GAGG;AACI,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAAjD,QAAA,MAAM,UAA2C;AAE9D;;;GAGG;AACI,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAAvD,QAAA,SAAS,aAA8C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.test.d.ts","sourceRoot":"","sources":["../../src/hash.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// DXOS testing browser.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
//
|
|
5
|
+
// Copyright 2020 DXOS.org
|
|
6
|
+
//
|
|
7
|
+
const chai_1 = require("chai");
|
|
8
|
+
const hash_1 = require("./hash");
|
|
9
|
+
it('SHA1', function () {
|
|
10
|
+
const hashed = (0, hash_1.sha1)('Test message');
|
|
11
|
+
(0, chai_1.expect)(hashed).to.equal('8de39b4722207f2da2a831e8734f02e740c15738');
|
|
12
|
+
});
|
|
13
|
+
it('SHA256', function () {
|
|
14
|
+
const hashed = (0, hash_1.sha256)('Test message');
|
|
15
|
+
(0, chai_1.expect)(hashed).to.equal('c0719e9a8d5d838d861dc6f675c899d2b309a3a65bb9fe6b11e5afcbf9a2c0b1');
|
|
16
|
+
});
|
|
17
|
+
it('SHA512', function () {
|
|
18
|
+
const hashed = (0, hash_1.sha512)('Test message');
|
|
19
|
+
(0, chai_1.expect)(hashed).to.equal('48418241a4d779508a6b98e623328a68f7f0bf27fd101bb2c89384827bfc0740' +
|
|
20
|
+
'3fefd5855576f1824fcd7acd233541514240c2bcf0fa9732ebb8f166a7c38bdf');
|
|
21
|
+
});
|
|
22
|
+
it('RIPEMD160', function () {
|
|
23
|
+
const hashed = (0, hash_1.ripemd160)('Test message');
|
|
24
|
+
(0, chai_1.expect)(hashed).to.equal('24b83e2457880c95d2e3c3c6b98e24ab170b1e11');
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=hash.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.test.js","sourceRoot":"","sources":["../../src/hash.test.ts"],"names":[],"mappings":";AAAA,wBAAwB;;AAExB,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF,+BAA8B;AAE9B,iCAAyD;AAEzD,EAAE,CAAC,MAAM,EAAE;IACT,MAAM,MAAM,GAAG,IAAA,WAAI,EAAC,cAAc,CAAC,CAAC;IACpC,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,QAAQ,EAAE;IACX,MAAM,MAAM,GAAG,IAAA,aAAM,EAAC,cAAc,CAAC,CAAC;IACtC,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,kEAAkE,CAAC,CAAC;AAC9F,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,QAAQ,EAAE;IACX,MAAM,MAAM,GAAG,IAAA,aAAM,EAAC,cAAc,CAAC,CAAC;IACtC,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CACrB,kEAAkE;QAChE,kEAAkE,CACrE,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,WAAW,EAAE;IACd,MAAM,MAAM,GAAG,IAAA,gBAAS,EAAC,cAAc,CAAC,CAAC;IACzC,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2020 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./encrypt"), exports);
|
|
21
|
+
__exportStar(require("./hash"), exports);
|
|
22
|
+
__exportStar(require("./keys"), exports);
|
|
23
|
+
__exportStar(require("./signer"), exports);
|
|
24
|
+
__exportStar(require("./subtle"), exports);
|
|
25
|
+
__exportStar(require("./validator"), exports);
|
|
26
|
+
__exportStar(require("./verify"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,4CAA0B;AAC1B,yCAAuB;AACvB,yCAAuB;AACvB,2CAAyB;AACzB,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { KeyPair, PublicKey, PublicKeyLike } from '@dxos/keys';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated
|
|
4
|
+
*/
|
|
5
|
+
export declare const createId: () => string;
|
|
6
|
+
export declare const SIGNATURE_LENGTH = 64;
|
|
7
|
+
export declare const zeroKey: () => Uint8Array;
|
|
8
|
+
export declare const createKeyPair: (seed?: Buffer) => KeyPair;
|
|
9
|
+
export declare const validateKeyPair: (publicKey: PublicKey, secretKey: Buffer) => boolean;
|
|
10
|
+
export declare const discoveryKey: (key: PublicKeyLike) => Buffer;
|
|
11
|
+
/**
|
|
12
|
+
* Return random bytes of length.
|
|
13
|
+
* @param [length=32]
|
|
14
|
+
* @return {Buffer}
|
|
15
|
+
*/
|
|
16
|
+
export declare const randomBytes: (length?: number) => Buffer;
|
|
17
|
+
/**
|
|
18
|
+
* Sign the contents of message with secret_key
|
|
19
|
+
* @param {Buffer} message
|
|
20
|
+
* @param {Buffer} secretKey
|
|
21
|
+
* @returns {Buffer} signature
|
|
22
|
+
*/
|
|
23
|
+
export declare const sign: (message: Buffer, secretKey: Buffer) => Buffer;
|
|
24
|
+
/**
|
|
25
|
+
* Verifies the signature against the message and public_key.
|
|
26
|
+
* @param {Buffer} message
|
|
27
|
+
* @param {Buffer} publicKey
|
|
28
|
+
* @param {Buffer} signature
|
|
29
|
+
* @return {boolean}
|
|
30
|
+
*/
|
|
31
|
+
export declare const verify: (message: Buffer, signature: Buffer, publicKey: Buffer) => boolean;
|
|
32
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/keys.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAwC,MAAM,YAAY,CAAC;AAErG;;GAEG;AAEH,eAAO,MAAM,QAAQ,QAAO,MAA8C,CAAC;AAE3E,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,eAAO,MAAM,OAAO,kBAA2B,CAAC;AAEhD,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,OAQ7C,CAAC;AAGF,eAAO,MAAM,eAAe,cAAe,SAAS,aAAa,MAAM,YACC,CAAC;AAGzE,eAAO,MAAM,YAAY,QAAS,aAAa,KAAG,MACY,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,WAAW,uBAAkB,MAAoC,CAAC;AAE/E;;;;;GAKG;AACH,eAAO,MAAM,IAAI,YAAa,MAAM,aAAa,MAAM,KAAG,MAKzD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,YAAa,MAAM,aAAa,MAAM,aAAa,MAAM,KAAG,OAM9E,CAAC"}
|
package/dist/src/keys.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2020 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.verify = exports.sign = exports.randomBytes = exports.discoveryKey = exports.validateKeyPair = exports.createKeyPair = exports.zeroKey = exports.SIGNATURE_LENGTH = exports.createId = void 0;
|
|
10
|
+
const hypercore_crypto_1 = __importDefault(require("hypercore-crypto"));
|
|
11
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
12
|
+
const keys_1 = require("@dxos/keys");
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated
|
|
15
|
+
*/
|
|
16
|
+
// TODO(burdon): Remove.
|
|
17
|
+
const createId = () => keys_1.PublicKey.stringify((0, exports.randomBytes)(32));
|
|
18
|
+
exports.createId = createId;
|
|
19
|
+
exports.SIGNATURE_LENGTH = 64;
|
|
20
|
+
const zeroKey = () => new Uint8Array(32); // TODO(burdon): Remove?
|
|
21
|
+
exports.zeroKey = zeroKey;
|
|
22
|
+
const createKeyPair = (seed) => {
|
|
23
|
+
if (seed) {
|
|
24
|
+
(0, node_assert_1.default)(seed.length >= 32, 'Seedphrase too sort. Expecting length of 32.');
|
|
25
|
+
return hypercore_crypto_1.default.keyPair(seed.slice(0, 32));
|
|
26
|
+
}
|
|
27
|
+
// TODO(burdon): Enable seed for debugging.
|
|
28
|
+
return hypercore_crypto_1.default.keyPair();
|
|
29
|
+
};
|
|
30
|
+
exports.createKeyPair = createKeyPair;
|
|
31
|
+
// TODO(burdon): Buffer.
|
|
32
|
+
const validateKeyPair = (publicKey, secretKey) => hypercore_crypto_1.default.validateKeyPair({ publicKey: publicKey.asBuffer(), secretKey });
|
|
33
|
+
exports.validateKeyPair = validateKeyPair;
|
|
34
|
+
// TODO(dmaretskyi): Slicing because webcrypto keys are too long.
|
|
35
|
+
const discoveryKey = (key) => hypercore_crypto_1.default.discoveryKey(keys_1.PublicKey.from(key).asBuffer().slice(1));
|
|
36
|
+
exports.discoveryKey = discoveryKey;
|
|
37
|
+
/**
|
|
38
|
+
* Return random bytes of length.
|
|
39
|
+
* @param [length=32]
|
|
40
|
+
* @return {Buffer}
|
|
41
|
+
*/
|
|
42
|
+
const randomBytes = (length = 32) => hypercore_crypto_1.default.randomBytes(length);
|
|
43
|
+
exports.randomBytes = randomBytes;
|
|
44
|
+
/**
|
|
45
|
+
* Sign the contents of message with secret_key
|
|
46
|
+
* @param {Buffer} message
|
|
47
|
+
* @param {Buffer} secretKey
|
|
48
|
+
* @returns {Buffer} signature
|
|
49
|
+
*/
|
|
50
|
+
const sign = (message, secretKey) => {
|
|
51
|
+
(0, node_assert_1.default)(Buffer.isBuffer(message));
|
|
52
|
+
(0, node_assert_1.default)(Buffer.isBuffer(secretKey) && secretKey.length === keys_1.SECRET_KEY_LENGTH);
|
|
53
|
+
return hypercore_crypto_1.default.sign(message, secretKey);
|
|
54
|
+
};
|
|
55
|
+
exports.sign = sign;
|
|
56
|
+
/**
|
|
57
|
+
* Verifies the signature against the message and public_key.
|
|
58
|
+
* @param {Buffer} message
|
|
59
|
+
* @param {Buffer} publicKey
|
|
60
|
+
* @param {Buffer} signature
|
|
61
|
+
* @return {boolean}
|
|
62
|
+
*/
|
|
63
|
+
const verify = (message, signature, publicKey) => {
|
|
64
|
+
(0, node_assert_1.default)(Buffer.isBuffer(message));
|
|
65
|
+
(0, node_assert_1.default)(Buffer.isBuffer(signature) && signature.length === exports.SIGNATURE_LENGTH);
|
|
66
|
+
(0, node_assert_1.default)(Buffer.isBuffer(publicKey) && publicKey.length === keys_1.PUBLIC_KEY_LENGTH);
|
|
67
|
+
return hypercore_crypto_1.default.verify(message, signature, publicKey);
|
|
68
|
+
};
|
|
69
|
+
exports.verify = verify;
|
|
70
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/keys.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,wEAAsC;AACtC,8DAAiC;AAEjC,qCAAqG;AAErG;;GAEG;AACH,wBAAwB;AACjB,MAAM,QAAQ,GAAG,GAAW,EAAE,CAAC,gBAAS,CAAC,SAAS,CAAC,IAAA,mBAAW,EAAC,EAAE,CAAC,CAAC,CAAC;AAA9D,QAAA,QAAQ,YAAsD;AAE9D,QAAA,gBAAgB,GAAG,EAAE,CAAC;AAE5B,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,wBAAwB;AAA5D,QAAA,OAAO,WAA4B;AAEzC,MAAM,aAAa,GAAG,CAAC,IAAa,EAAW,EAAE;IACtD,IAAI,IAAI,EAAE;QACR,IAAA,qBAAM,EAAC,IAAI,CAAC,MAAM,IAAI,EAAE,EAAE,8CAA8C,CAAC,CAAC;QAC1E,OAAO,0BAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;KAC1C;IAED,2CAA2C;IAC3C,OAAO,0BAAM,CAAC,OAAO,EAAE,CAAC;AAC1B,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB;AAEF,wBAAwB;AACjB,MAAM,eAAe,GAAG,CAAC,SAAoB,EAAE,SAAiB,EAAE,EAAE,CACzE,0BAAM,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AAD5D,QAAA,eAAe,mBAC6C;AAEzE,iEAAiE;AAC1D,MAAM,YAAY,GAAG,CAAC,GAAkB,EAAU,EAAE,CACzD,0BAAM,CAAC,YAAY,CAAC,gBAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AADlD,QAAA,YAAY,gBACsC;AAE/D;;;;GAIG;AACI,MAAM,WAAW,GAAG,CAAC,MAAM,GAAG,EAAE,EAAU,EAAE,CAAC,0BAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAAlE,QAAA,WAAW,eAAuD;AAE/E;;;;;GAKG;AACI,MAAM,IAAI,GAAG,CAAC,OAAe,EAAE,SAAiB,EAAU,EAAE;IACjE,IAAA,qBAAM,EAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACjC,IAAA,qBAAM,EAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,KAAK,wBAAiB,CAAC,CAAC;IAE7E,OAAO,0BAAM,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACzC,CAAC,CAAC;AALW,QAAA,IAAI,QAKf;AAEF;;;;;;GAMG;AACI,MAAM,MAAM,GAAG,CAAC,OAAe,EAAE,SAAiB,EAAE,SAAiB,EAAW,EAAE;IACvF,IAAA,qBAAM,EAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACjC,IAAA,qBAAM,EAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,KAAK,wBAAgB,CAAC,CAAC;IAC5E,IAAA,qBAAM,EAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,KAAK,wBAAiB,CAAC,CAAC;IAE7E,OAAO,0BAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AACtD,CAAC,CAAC;AANW,QAAA,MAAM,UAMjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.test.d.ts","sourceRoot":"","sources":["../../src/keys.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2020 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chai_1 = require("chai");
|
|
7
|
+
const keys_1 = require("./keys");
|
|
8
|
+
it('Create id is unique', function () {
|
|
9
|
+
(0, chai_1.expect)((0, keys_1.createId)()).not.to.equal((0, keys_1.createId)());
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=keys.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.test.js","sourceRoot":"","sources":["../../src/keys.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;AAEF,+BAA8B;AAE9B,iCAAkC;AAElC,EAAE,CAAC,qBAAqB,EAAE;IACxB,IAAA,aAAM,EAAC,IAAA,eAAQ,GAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,IAAA,eAAQ,GAAE,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PublicKey } from '@dxos/keys';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
export interface Signer {
|
|
6
|
+
/**
|
|
7
|
+
* Sign a message with the given key.
|
|
8
|
+
* Key must be present in the keyring.
|
|
9
|
+
*/
|
|
10
|
+
sign: (key: PublicKey, message: Uint8Array) => Promise<Uint8Array>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;OAGG;IACH,IAAI,EAAE,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CACpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/signer.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subtle.d.ts","sourceRoot":"","sources":["../../src/subtle.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AAE1C,eAAO,MAAM,YAAY,mCAA8B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2022 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.subtleCrypto = void 0;
|
|
30
|
+
const nodeCrypto = __importStar(require("node:crypto"));
|
|
31
|
+
exports.subtleCrypto = nodeCrypto.webcrypto.subtle;
|
|
32
|
+
//# sourceMappingURL=subtle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subtle.js","sourceRoot":"","sources":["../../src/subtle.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,wDAA0C;AAE7B,QAAA,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,eAAO,MAAM,qBAAqB,cAAe,MAAM,eAAe,MAAM,aAAa,MAAM,YACnC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2020 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getSignatureValidator = void 0;
|
|
7
|
+
const hypercore_crypto_1 = require("hypercore-crypto");
|
|
8
|
+
const keys_1 = require("@dxos/keys");
|
|
9
|
+
/**
|
|
10
|
+
* Generator for signature validation function.
|
|
11
|
+
* @param {String} publicKey
|
|
12
|
+
*/
|
|
13
|
+
const getSignatureValidator = (publicKey) => (message, signature) => (0, hypercore_crypto_1.verify)(message, signature, keys_1.PublicKey.bufferize(publicKey));
|
|
14
|
+
exports.getSignatureValidator = getSignatureValidator;
|
|
15
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAEF,uDAA0C;AAE1C,qCAAuC;AAEvC;;;GAGG;AACI,MAAM,qBAAqB,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,CAAC,OAAe,EAAE,SAAiB,EAAE,EAAE,CACjG,IAAA,yBAAM,EAAC,OAAO,EAAE,SAAS,EAAE,gBAAS,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;AADhD,QAAA,qBAAqB,yBAC2B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/verify.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC;;GAEG;AACH,eAAO,MAAM,eAAe,QAAe,SAAS,WAAW,UAAU,aAAa,UAAU,KAAG,QAAQ,OAAO,CA2BjH,CAAC"}
|