@atomicfinance/crypto 3.4.7 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/lib/index.js +89 -0
- package/package.json +1 -1
- package/CHANGELOG.md +0 -89
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ exports.ensureBuffer = ensureBuffer;
|
|
|
44
44
|
* @return {string} Returns the hash of a string.
|
|
45
45
|
*/
|
|
46
46
|
function hashToHex(algorithm, message) {
|
|
47
|
-
return crypto_hashing_1.default(algorithm, ensureBuffer(message)).toString('hex');
|
|
47
|
+
return (0, crypto_hashing_1.default)(algorithm, ensureBuffer(message)).toString('hex');
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Get hash160 of message.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AA+F1B,iBA/FK,gBAAM,CA+FL;AA9FR,gDAA0B;AAwFxB,iBAxFK,cAAM,CAwFL;AAvFR,oEAAwC;AAExC,SAAS,KAAK,CAAC,GAAW;IACxB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,kBAAkB,CAAC;QAAE,OAAO,KAAK,CAAC;IAEjD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEpD,OAAO,GAAG,KAAK,GAAG,CAAC,WAAW,EAAE,CAAC;AACnC,CAAC;AA2FC,sBAAK;AAzFP;;;;GAIG;AACH,SAAS,YAAY,CAAC,OAA8B;IAClD,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAE7C,QAAQ,OAAO,OAAO,EAAE;QACtB,KAAK,QAAQ;YACX,OAA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
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isHex = exports.padHexStart = exports.ensureBuffer = exports.hash160 = exports.ripemd160 = exports.sha256 = exports.bech32 = exports.base58 = void 0;
|
|
7
|
+
const bech32_1 = __importDefault(require("bech32"));
|
|
8
|
+
exports.bech32 = bech32_1.default;
|
|
9
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
10
|
+
exports.base58 = bs58_1.default;
|
|
11
|
+
const crypto_hashing_1 = __importDefault(require("crypto-hashing"));
|
|
12
|
+
function isHex(hex) {
|
|
13
|
+
if (!hex.match(/([0-9]|[a-f])/gim))
|
|
14
|
+
return false;
|
|
15
|
+
const buf = Buffer.from(hex, 'hex').toString('hex');
|
|
16
|
+
return buf === hex.toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
exports.isHex = isHex;
|
|
19
|
+
/**
|
|
20
|
+
* Ensure message is in buffer format.
|
|
21
|
+
* @param {string} message - any string.
|
|
22
|
+
* @return {string} Returns Buffer.
|
|
23
|
+
*/
|
|
24
|
+
function ensureBuffer(message) {
|
|
25
|
+
if (Buffer.isBuffer(message))
|
|
26
|
+
return message;
|
|
27
|
+
switch (typeof message) {
|
|
28
|
+
case 'string':
|
|
29
|
+
message = isHex(message)
|
|
30
|
+
? Buffer.from(message, 'hex')
|
|
31
|
+
: Buffer.from(message);
|
|
32
|
+
break;
|
|
33
|
+
case 'object':
|
|
34
|
+
message = Buffer.from(JSON.stringify(message));
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
return Buffer.isBuffer(message) ? message : false;
|
|
38
|
+
}
|
|
39
|
+
exports.ensureBuffer = ensureBuffer;
|
|
40
|
+
/**
|
|
41
|
+
* Get hash of a message in hex.
|
|
42
|
+
* @param {!string} algorithm - Hashing algorithm.
|
|
43
|
+
* @param {!string|Buffer} message - Message to be hashed.
|
|
44
|
+
* @return {string} Returns the hash of a string.
|
|
45
|
+
*/
|
|
46
|
+
function hashToHex(algorithm, message) {
|
|
47
|
+
return (0, crypto_hashing_1.default)(algorithm, ensureBuffer(message)).toString('hex');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get hash160 of message.
|
|
51
|
+
* @param {!string|Buffer} message - message in string or Buffer.
|
|
52
|
+
* @return {string} Returns the hash160 of a string.
|
|
53
|
+
*/
|
|
54
|
+
function hash160(message) {
|
|
55
|
+
return hashToHex('hash160', message);
|
|
56
|
+
}
|
|
57
|
+
exports.hash160 = hash160;
|
|
58
|
+
/**
|
|
59
|
+
* Get sha256 of message.
|
|
60
|
+
* @param {!string|Buffer} message - message in string or Buffer.
|
|
61
|
+
* @return {string} Returns the sha256 of a string.
|
|
62
|
+
*/
|
|
63
|
+
function sha256(message) {
|
|
64
|
+
return hashToHex('sha256', message);
|
|
65
|
+
}
|
|
66
|
+
exports.sha256 = sha256;
|
|
67
|
+
/**
|
|
68
|
+
* Get ripemd160 of message.
|
|
69
|
+
* @param {!string|Buffer} message - message in string or Buffer.
|
|
70
|
+
* @return {string} Returns the ripemd160 of a string.
|
|
71
|
+
*/
|
|
72
|
+
function ripemd160(message) {
|
|
73
|
+
return hashToHex('ripemd160', message);
|
|
74
|
+
}
|
|
75
|
+
exports.ripemd160 = ripemd160;
|
|
76
|
+
/**
|
|
77
|
+
* Pad a hex string with '0'
|
|
78
|
+
* @param {string} hex - The hex string to pad.
|
|
79
|
+
* @param {number} lengthBytes - The length of the final string in bytes
|
|
80
|
+
* @return {string} Returns a padded string with length greater or equal to the given length
|
|
81
|
+
* rounded up to the nearest even number.
|
|
82
|
+
*/
|
|
83
|
+
function padHexStart(hex, lengthBytes) {
|
|
84
|
+
let lengthString = lengthBytes * 2 || hex.length;
|
|
85
|
+
lengthString += lengthString % 2;
|
|
86
|
+
return hex.padStart(lengthString, '0');
|
|
87
|
+
}
|
|
88
|
+
exports.padHexStart = padHexStart;
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
package/CHANGELOG.md
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# @atomicfinance/crypto
|
|
2
|
-
|
|
3
|
-
## 3.4.7
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- 0ba01ef: Bump @node-dlc to 0.23.6
|
|
8
|
-
|
|
9
|
-
## 3.4.6
|
|
10
|
-
|
|
11
|
-
### Patch Changes
|
|
12
|
-
|
|
13
|
-
- b765b9c: Bump nodep-dlc to 0.23.5
|
|
14
|
-
|
|
15
|
-
## 3.4.5
|
|
16
|
-
|
|
17
|
-
### Patch Changes
|
|
18
|
-
|
|
19
|
-
- 74b7a4f: Bump node-dlc to 0.23.4
|
|
20
|
-
|
|
21
|
-
## 3.4.4
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
24
|
-
|
|
25
|
-
- cc8f06a: Bump node-dlc to 0.23.3
|
|
26
|
-
|
|
27
|
-
## 3.4.3
|
|
28
|
-
|
|
29
|
-
### Patch Changes
|
|
30
|
-
|
|
31
|
-
- db49017: Bump node-dlc to 0.23.2 for all packages
|
|
32
|
-
|
|
33
|
-
## 3.4.2
|
|
34
|
-
|
|
35
|
-
### Patch Changes
|
|
36
|
-
|
|
37
|
-
- e701ba6: Bump node-dlc- to 0.23.1 and add node-dlc batch tx builder validation tests
|
|
38
|
-
|
|
39
|
-
## 3.4.1
|
|
40
|
-
|
|
41
|
-
### Patch Changes
|
|
42
|
-
|
|
43
|
-
- 9781efe: Add getInputsForDualFunding functionality and bump @node-dlc
|
|
44
|
-
|
|
45
|
-
## 3.4.0
|
|
46
|
-
|
|
47
|
-
### Minor Changes
|
|
48
|
-
|
|
49
|
-
- 314d7d7: Add batch dlc funding transactions
|
|
50
|
-
|
|
51
|
-
## 3.3.1
|
|
52
|
-
|
|
53
|
-
### Patch Changes
|
|
54
|
-
|
|
55
|
-
- 7f6f4a8: Fix rounding error with find payout
|
|
56
|
-
|
|
57
|
-
## 3.3.0
|
|
58
|
-
|
|
59
|
-
### Minor Changes
|
|
60
|
-
|
|
61
|
-
- 4a512ee: Fix find outcome index for hyperbola payout curve edge case
|
|
62
|
-
|
|
63
|
-
## 3.2.5
|
|
64
|
-
|
|
65
|
-
## 3.2.4
|
|
66
|
-
|
|
67
|
-
### Patch Changes
|
|
68
|
-
|
|
69
|
-
- 177b76a: Upgrade node-dlc to 0.22.4
|
|
70
|
-
|
|
71
|
-
## 3.2.3
|
|
72
|
-
|
|
73
|
-
## 3.2.2
|
|
74
|
-
|
|
75
|
-
## 3.2.1
|
|
76
|
-
|
|
77
|
-
## 3.2.0
|
|
78
|
-
|
|
79
|
-
## 3.1.1
|
|
80
|
-
|
|
81
|
-
## 3.1.0
|
|
82
|
-
|
|
83
|
-
## 3.0.1
|
|
84
|
-
|
|
85
|
-
## 3.0.0
|
|
86
|
-
|
|
87
|
-
### Major Changes
|
|
88
|
-
|
|
89
|
-
- a06082e: Create unified standalone `bitcoin-abstraction-layer` package
|