@transia/isomorphic 1.0.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.
Files changed (88) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +124 -0
  3. package/dist/internal/normalizeInput.d.ts +9 -0
  4. package/dist/internal/normalizeInput.d.ts.map +1 -0
  5. package/dist/internal/normalizeInput.js +13 -0
  6. package/dist/internal/normalizeInput.js.map +1 -0
  7. package/dist/internal/types.d.ts +31 -0
  8. package/dist/internal/types.d.ts.map +1 -0
  9. package/dist/internal/types.js +3 -0
  10. package/dist/internal/types.js.map +1 -0
  11. package/dist/internal/wrapCryptoCreateHash.d.ts +11 -0
  12. package/dist/internal/wrapCryptoCreateHash.d.ts.map +1 -0
  13. package/dist/internal/wrapCryptoCreateHash.js +32 -0
  14. package/dist/internal/wrapCryptoCreateHash.js.map +1 -0
  15. package/dist/internal/wrapNoble.d.ts +9 -0
  16. package/dist/internal/wrapNoble.d.ts.map +1 -0
  17. package/dist/internal/wrapNoble.js +31 -0
  18. package/dist/internal/wrapNoble.js.map +1 -0
  19. package/dist/ripemd160/browser.d.ts +5 -0
  20. package/dist/ripemd160/browser.d.ts.map +1 -0
  21. package/dist/ripemd160/browser.js +13 -0
  22. package/dist/ripemd160/browser.js.map +1 -0
  23. package/dist/ripemd160/index.d.ts +5 -0
  24. package/dist/ripemd160/index.d.ts.map +1 -0
  25. package/dist/ripemd160/index.js +13 -0
  26. package/dist/ripemd160/index.js.map +1 -0
  27. package/dist/sha256/browser.d.ts +5 -0
  28. package/dist/sha256/browser.d.ts.map +1 -0
  29. package/dist/sha256/browser.js +13 -0
  30. package/dist/sha256/browser.js.map +1 -0
  31. package/dist/sha256/index.d.ts +5 -0
  32. package/dist/sha256/index.d.ts.map +1 -0
  33. package/dist/sha256/index.js +13 -0
  34. package/dist/sha256/index.js.map +1 -0
  35. package/dist/sha512/browser.d.ts +5 -0
  36. package/dist/sha512/browser.d.ts.map +1 -0
  37. package/dist/sha512/browser.js +13 -0
  38. package/dist/sha512/browser.js.map +1 -0
  39. package/dist/sha512/index.d.ts +5 -0
  40. package/dist/sha512/index.d.ts.map +1 -0
  41. package/dist/sha512/index.js +13 -0
  42. package/dist/sha512/index.js.map +1 -0
  43. package/dist/utils/browser.d.ts +8 -0
  44. package/dist/utils/browser.d.ts.map +1 -0
  45. package/dist/utils/browser.js +56 -0
  46. package/dist/utils/browser.js.map +1 -0
  47. package/dist/utils/index.d.ts +9 -0
  48. package/dist/utils/index.d.ts.map +1 -0
  49. package/dist/utils/index.js +85 -0
  50. package/dist/utils/index.js.map +1 -0
  51. package/dist/utils/shared.d.ts +4 -0
  52. package/dist/utils/shared.d.ts.map +1 -0
  53. package/dist/utils/shared.js +24 -0
  54. package/dist/utils/shared.js.map +1 -0
  55. package/dist/utils/types.d.ts +34 -0
  56. package/dist/utils/types.d.ts.map +1 -0
  57. package/dist/utils/types.js +3 -0
  58. package/dist/utils/types.js.map +1 -0
  59. package/dist/ws/browser.d.ts +52 -0
  60. package/dist/ws/browser.d.ts.map +1 -0
  61. package/dist/ws/browser.js +71 -0
  62. package/dist/ws/browser.js.map +1 -0
  63. package/dist/ws/index.d.ts +6 -0
  64. package/dist/ws/index.d.ts.map +1 -0
  65. package/dist/ws/index.js +14 -0
  66. package/dist/ws/index.js.map +1 -0
  67. package/package.json +52 -0
  68. package/ripemd160/package.json +7 -0
  69. package/sha256/package.json +7 -0
  70. package/sha512/package.json +7 -0
  71. package/src/internal/normalizeInput.ts +11 -0
  72. package/src/internal/types.ts +33 -0
  73. package/src/internal/wrapCryptoCreateHash.ts +32 -0
  74. package/src/internal/wrapNoble.ts +28 -0
  75. package/src/ripemd160/browser.ts +8 -0
  76. package/src/ripemd160/index.ts +7 -0
  77. package/src/sha256/browser.ts +8 -0
  78. package/src/sha256/index.ts +7 -0
  79. package/src/sha512/browser.ts +8 -0
  80. package/src/sha512/index.ts +7 -0
  81. package/src/utils/browser.ts +54 -0
  82. package/src/utils/index.ts +93 -0
  83. package/src/utils/shared.ts +21 -0
  84. package/src/utils/types.ts +37 -0
  85. package/src/ws/browser.ts +105 -0
  86. package/src/ws/index.ts +10 -0
  87. package/utils/package.json +7 -0
  88. package/ws/package.json +11 -0
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2023 The XRPL developers
4
+
5
+ Permission to use, copy, modify, and distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # @xrplf/isomorphic
2
+
3
+ A collection of isomorphic implementations of crypto and utility functions.
4
+
5
+ Browser implementations of cryptographic functions use `@noble/hashes` and `crypto` for node .
6
+
7
+ ### Hashes
8
+
9
+ All hash functions operate similarly to `@noble/hashes` and have the following properties:
10
+
11
+ - They can be called directly by providing a Uint8Array or string which will be converted into a UInt8Array via UTF-8 encoding (not hex).
12
+ - They all return a UInt8Array.
13
+
14
+ ```
15
+ function hash(message: Uint8Array | string): Uint8Array;
16
+ hash(new Uint8Array([1, 3]));
17
+ hash('string') == hash(new TextEncoder().encode('string'));
18
+ ```
19
+
20
+ All hash functions can be constructed via `hash.create()` method:
21
+
22
+ - The result is `Hash` subclass instance, which has `update()` and `digest()` methods.
23
+ - `digest()` finalizes the hash and makes it no longer usable
24
+
25
+ ```typescript
26
+ hash
27
+ .create()
28
+ .update(new Uint8Array([1, 3]))
29
+ .digest();
30
+ ```
31
+
32
+ ### `@xrplf/isomorphic/ripemd160`
33
+ ```typescript
34
+ import { ripemd160 } from '@transia/isomorphic/ripemd160';
35
+ const hashA = ripemd160('abc');
36
+ const hashB = ripemd160
37
+ .create()
38
+ .update(Uint8Array.from([1, 2, 3]))
39
+ .digest();
40
+ ```
41
+
42
+ ### `@xrplf/isomorphic/sha256`
43
+
44
+ ```typescript
45
+ import { sha256 } from '@transia/isomorphic/sha256';
46
+ const hashA = sha256('abc');
47
+ const hashB = sha256
48
+ .create()
49
+ .update(Uint8Array.from([1, 2, 3]))
50
+ .digest();
51
+ ```
52
+
53
+ ### `@xrplf/isomorphic/sha512`
54
+
55
+ ```typescript
56
+ import { sha512 } from '@transia/isomorphic/sha512';
57
+ const hashA = sha512('abc');
58
+ const hashB = sha512
59
+ .create()
60
+ .update(Uint8Array.from([1, 2, 3]))
61
+ .digest();
62
+ ```
63
+
64
+ ## Utilities
65
+
66
+ ### `@xrplf/isomorphic/utils`
67
+
68
+ #### randomBytes
69
+
70
+ Create an UInt8Array of the supplied size
71
+
72
+ ```typescript
73
+ import { randomBytes } from @xrplf/isomorphic/utils
74
+
75
+ console.log(randomBytes(12)) // Uint8Array(12) [95, 236, 188, 55, 208, 128, 161, 249, 171, 57, 141, 7]
76
+ ```
77
+
78
+ #### bytesToHex
79
+
80
+ Convert an UInt8Array to hex.
81
+
82
+ ```typescript
83
+ import { bytesToHex } from @xrplf/isomorphic/utils
84
+
85
+ console.log(bytesToHex([222, 173, 190, 239])) // "DEADBEEF"
86
+ ```
87
+
88
+ #### hexToBytes
89
+
90
+ Convert hex to an UInt8Array.
91
+
92
+ ```typescript
93
+ import { hexToBytes } from @xrplf/isomorphic/utils
94
+
95
+ console.log(hexToBytes('DEADBEEF')) // [222, 173, 190, 239]
96
+ ```
97
+
98
+ #### hexToString
99
+
100
+ Converts hex to its string equivalent. Useful to read the Domain field and some Memos.
101
+
102
+ ```typescript
103
+ import { hexToString } from @xrplf/isomorphic/utils
104
+
105
+ console.log(hexToString('6465616462656566D68D')) // "deadbeef֍"
106
+ ```
107
+
108
+ #### stringToHex
109
+
110
+ Converts a utf-8 to its hex equivalent. Useful for Memos.
111
+
112
+ ```typescript
113
+ import { stringToHex } from @xrplf/isomorphic/utils
114
+
115
+ console.log(stringToHex('deadbeef֍')) // "6465616462656566D68D"
116
+ ```
117
+
118
+ ### `@xrplf/isomorphic/ws`
119
+
120
+ ```typescript
121
+ import WebSocket from '@transia/isomorphic/ws'
122
+
123
+ const socket = new WebSocket('wss://localhost:8080')
124
+ ```
@@ -0,0 +1,9 @@
1
+ import { Input } from './types';
2
+ /**
3
+ * Normalize a string, number array, or Uint8Array to a string or Uint8Array.
4
+ * Both node and noble lib functions accept these types.
5
+ *
6
+ * @param input - value to normalize
7
+ */
8
+ export default function normalizeInput(input: Input): string | Uint8Array;
9
+ //# sourceMappingURL=normalizeInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeInput.d.ts","sourceRoot":"","sources":["../../src/internal/normalizeInput.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,UAAU,CAExE"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Normalize a string, number array, or Uint8Array to a string or Uint8Array.
5
+ * Both node and noble lib functions accept these types.
6
+ *
7
+ * @param input - value to normalize
8
+ */
9
+ function normalizeInput(input) {
10
+ return Array.isArray(input) ? new Uint8Array(input) : input;
11
+ }
12
+ exports.default = normalizeInput;
13
+ //# sourceMappingURL=normalizeInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeInput.js","sourceRoot":"","sources":["../../src/internal/normalizeInput.ts"],"names":[],"mappings":";;AAEA;;;;;GAKG;AACH,SAAwB,cAAc,CAAC,KAAY;IACjD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AAC7D,CAAC;AAFD,iCAEC"}
@@ -0,0 +1,31 @@
1
+ export type ByteEncodedString = string;
2
+ export type Input = Uint8Array | number[] | ByteEncodedString;
3
+ /**
4
+ * A stripped down isomorphic hash inspired by node's `crypto.Hash`
5
+ */
6
+ export interface Hash {
7
+ /**
8
+ * Updates the hash content with the given data,
9
+ *
10
+ * @param data - a byte encoded string, an array of numbers or a Uint8Array
11
+ */
12
+ update: (data: Input) => this;
13
+ /**
14
+ * Calculates the digest of all the data passed to be hashed and returns a Uint8Array
15
+ */
16
+ digest: () => Uint8Array;
17
+ }
18
+ export interface HashFn {
19
+ /**
20
+ * Produces a Uint8Array for the given hash contents
21
+ * Shorthand for calling `create`, `update`, and then `digest`
22
+ *
23
+ * @param data - a byte encoded string, an array of numbers or a Uint8Array
24
+ */
25
+ (data: Input): Uint8Array;
26
+ /**
27
+ * Creates a new empty `Hash`.
28
+ */
29
+ create: () => Hash;
30
+ }
31
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAA;AACtC,MAAM,MAAM,KAAK,GAAG,UAAU,GAAG,MAAM,EAAE,GAAG,iBAAiB,CAAA;AAE7D;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;;;OAIG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,IAAI,CAAA;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,UAAU,CAAA;CACzB;AAED,MAAM,WAAW,MAAM;IACrB;;;;;OAKG;IACH,CAAC,IAAI,EAAE,KAAK,GAAG,UAAU,CAAA;IAEzB;;OAEG;IACH,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import { createHash } from 'crypto';
3
+ import { HashFn } from './types';
4
+ /**
5
+ * Wrap createHash from node to provide an interface that is isomorphic
6
+ *
7
+ * @param type - the hash name
8
+ * @param fn - {createHash} the hash factory
9
+ */
10
+ export default function wrapCryptoCreateHash(type: string, fn: typeof createHash): HashFn;
11
+ //# sourceMappingURL=wrapCryptoCreateHash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapCryptoCreateHash.d.ts","sourceRoot":"","sources":["../../src/internal/wrapCryptoCreateHash.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAQ,MAAM,EAAS,MAAM,SAAS,CAAA;AAG7C;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,OAAO,UAAU,GACpB,MAAM,CAkBR"}
@@ -0,0 +1,32 @@
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
+ const normalizeInput_1 = __importDefault(require("./normalizeInput"));
7
+ /**
8
+ * Wrap createHash from node to provide an interface that is isomorphic
9
+ *
10
+ * @param type - the hash name
11
+ * @param fn - {createHash} the hash factory
12
+ */
13
+ function wrapCryptoCreateHash(type, fn) {
14
+ function hashFn(input) {
15
+ return fn(type).update((0, normalizeInput_1.default)(input)).digest();
16
+ }
17
+ hashFn.create = () => {
18
+ const hash = fn(type);
19
+ return {
20
+ update(input) {
21
+ hash.update((0, normalizeInput_1.default)(input));
22
+ return this;
23
+ },
24
+ digest() {
25
+ return hash.digest();
26
+ },
27
+ };
28
+ };
29
+ return hashFn;
30
+ }
31
+ exports.default = wrapCryptoCreateHash;
32
+ //# sourceMappingURL=wrapCryptoCreateHash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapCryptoCreateHash.js","sourceRoot":"","sources":["../../src/internal/wrapCryptoCreateHash.ts"],"names":[],"mappings":";;;;;AAEA,sEAA6C;AAE7C;;;;;GAKG;AACH,SAAwB,oBAAoB,CAC1C,IAAY,EACZ,EAAqB;IAErB,SAAS,MAAM,CAAC,KAAY;QAC1B,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAA,wBAAc,EAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAA;IACxD,CAAC;IAED,MAAM,CAAC,MAAM,GAAG,GAAS,EAAE;QACzB,MAAM,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;QACrB,OAAO;YACL,MAAM,CAAC,KAAY;gBACjB,IAAI,CAAC,MAAM,CAAC,IAAA,wBAAc,EAAC,KAAK,CAAC,CAAC,CAAA;gBAClC,OAAO,IAAI,CAAA;YACb,CAAC;YACD,MAAM;gBACJ,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;YACtB,CAAC;SACF,CAAA;IACH,CAAC,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AArBD,uCAqBC"}
@@ -0,0 +1,9 @@
1
+ import { CHash } from '@noble/hashes/utils';
2
+ import { HashFn } from './types';
3
+ /**
4
+ * Wrap a CHash object from @noble/hashes to provide a interface that is isomorphic
5
+ *
6
+ * @param chash - {CHash} hash function to wrap
7
+ */
8
+ export default function wrapNoble(chash: CHash): HashFn;
9
+ //# sourceMappingURL=wrapNoble.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapNoble.d.ts","sourceRoot":"","sources":["../../src/internal/wrapNoble.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAQ,MAAM,EAAS,MAAM,SAAS,CAAA;AAG7C;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAkBtD"}
@@ -0,0 +1,31 @@
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
+ const normalizeInput_1 = __importDefault(require("./normalizeInput"));
7
+ /**
8
+ * Wrap a CHash object from @noble/hashes to provide a interface that is isomorphic
9
+ *
10
+ * @param chash - {CHash} hash function to wrap
11
+ */
12
+ function wrapNoble(chash) {
13
+ function wrapped(input) {
14
+ return chash((0, normalizeInput_1.default)(input));
15
+ }
16
+ wrapped.create = () => {
17
+ const hash = chash.create();
18
+ return {
19
+ update(input) {
20
+ hash.update((0, normalizeInput_1.default)(input));
21
+ return this;
22
+ },
23
+ digest() {
24
+ return hash.digest();
25
+ },
26
+ };
27
+ };
28
+ return wrapped;
29
+ }
30
+ exports.default = wrapNoble;
31
+ //# sourceMappingURL=wrapNoble.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapNoble.js","sourceRoot":"","sources":["../../src/internal/wrapNoble.ts"],"names":[],"mappings":";;;;;AAEA,sEAA6C;AAE7C;;;;GAIG;AACH,SAAwB,SAAS,CAAC,KAAY;IAC5C,SAAS,OAAO,CAAC,KAAY;QAC3B,OAAO,KAAK,CAAC,IAAA,wBAAc,EAAC,KAAK,CAAC,CAAC,CAAA;IACrC,CAAC;IAED,OAAO,CAAC,MAAM,GAAG,GAAS,EAAE;QAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,CAAA;QAC3B,OAAO;YACL,MAAM,CAAC,KAAY;gBACjB,IAAI,CAAC,MAAM,CAAC,IAAA,wBAAc,EAAC,KAAK,CAAC,CAAC,CAAA;gBAClC,OAAO,IAAI,CAAA;YACb,CAAC;YACD,MAAM;gBACJ,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;YACtB,CAAC;SACF,CAAA;IACH,CAAC,CAAA;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAlBD,4BAkBC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Wrap noble-libs's ripemd160 implementation in HashFn
3
+ */
4
+ export declare const ripemd160: import("../internal/types").HashFn;
5
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/ripemd160/browser.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,SAAS,oCAAuB,CAAA"}
@@ -0,0 +1,13 @@
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.ripemd160 = void 0;
7
+ const ripemd160_1 = require("@noble/hashes/ripemd160");
8
+ const wrapNoble_1 = __importDefault(require("../internal/wrapNoble"));
9
+ /**
10
+ * Wrap noble-libs's ripemd160 implementation in HashFn
11
+ */
12
+ exports.ripemd160 = (0, wrapNoble_1.default)(ripemd160_1.ripemd160);
13
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/ripemd160/browser.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAgE;AAEhE,sEAA6C;AAE7C;;GAEG;AACU,QAAA,SAAS,GAAG,IAAA,mBAAS,EAAC,qBAAS,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Wrap node's native ripemd160 implementation in HashFn
3
+ */
4
+ export declare const ripemd160: import("../internal/types").HashFn;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ripemd160/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,SAAS,oCAAgD,CAAA"}
@@ -0,0 +1,13 @@
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.ripemd160 = void 0;
7
+ const crypto_1 = require("crypto");
8
+ const wrapCryptoCreateHash_1 = __importDefault(require("../internal/wrapCryptoCreateHash"));
9
+ /**
10
+ * Wrap node's native ripemd160 implementation in HashFn
11
+ */
12
+ exports.ripemd160 = (0, wrapCryptoCreateHash_1.default)('ripemd160', crypto_1.createHash);
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ripemd160/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AACnC,4FAAmE;AAEnE;;GAEG;AACU,QAAA,SAAS,GAAG,IAAA,8BAAoB,EAAC,WAAW,EAAE,mBAAU,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Wrap noble-libs's sha256 implementation in HashFn
3
+ */
4
+ export declare const sha256: import("../internal/types").HashFn;
5
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/sha256/browser.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,MAAM,oCAAuB,CAAA"}
@@ -0,0 +1,13 @@
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.sha256 = void 0;
7
+ const sha256_1 = require("@noble/hashes/sha256");
8
+ const wrapNoble_1 = __importDefault(require("../internal/wrapNoble"));
9
+ /**
10
+ * Wrap noble-libs's sha256 implementation in HashFn
11
+ */
12
+ exports.sha256 = (0, wrapNoble_1.default)(sha256_1.sha256);
13
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/sha256/browser.ts"],"names":[],"mappings":";;;;;;AAAA,iDAA0D;AAE1D,sEAA6C;AAE7C;;GAEG;AACU,QAAA,MAAM,GAAG,IAAA,mBAAS,EAAC,eAAS,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Wrap node's native sha256 implementation in HashFn
3
+ */
4
+ export declare const sha256: import("../internal/types").HashFn;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sha256/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,MAAM,oCAA6C,CAAA"}
@@ -0,0 +1,13 @@
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.sha256 = void 0;
7
+ const crypto_1 = require("crypto");
8
+ const wrapCryptoCreateHash_1 = __importDefault(require("../internal/wrapCryptoCreateHash"));
9
+ /**
10
+ * Wrap node's native sha256 implementation in HashFn
11
+ */
12
+ exports.sha256 = (0, wrapCryptoCreateHash_1.default)('sha256', crypto_1.createHash);
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sha256/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AACnC,4FAAmE;AAEnE;;GAEG;AACU,QAAA,MAAM,GAAG,IAAA,8BAAoB,EAAC,QAAQ,EAAE,mBAAU,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Wrap noble-libs's sha512 implementation in HashFn
3
+ */
4
+ export declare const sha512: import("../internal/types").HashFn;
5
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/sha512/browser.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,MAAM,oCAAuB,CAAA"}
@@ -0,0 +1,13 @@
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.sha512 = void 0;
7
+ const sha512_1 = require("@noble/hashes/sha512");
8
+ const wrapNoble_1 = __importDefault(require("../internal/wrapNoble"));
9
+ /**
10
+ * Wrap noble-libs's sha512 implementation in HashFn
11
+ */
12
+ exports.sha512 = (0, wrapNoble_1.default)(sha512_1.sha512);
13
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/sha512/browser.ts"],"names":[],"mappings":";;;;;;AAAA,iDAA0D;AAE1D,sEAA6C;AAE7C;;GAEG;AACU,QAAA,MAAM,GAAG,IAAA,mBAAS,EAAC,eAAS,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Wrap node's native sha512 implementation in HashFn
3
+ */
4
+ export declare const sha512: import("../internal/types").HashFn;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sha512/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,MAAM,oCAA6C,CAAA"}
@@ -0,0 +1,13 @@
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.sha512 = void 0;
7
+ const crypto_1 = require("crypto");
8
+ const wrapCryptoCreateHash_1 = __importDefault(require("../internal/wrapCryptoCreateHash"));
9
+ /**
10
+ * Wrap node's native sha512 implementation in HashFn
11
+ */
12
+ exports.sha512 = (0, wrapCryptoCreateHash_1.default)('sha512', crypto_1.createHash);
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sha512/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AACnC,4FAAmE;AAEnE;;GAEG;AACU,QAAA,MAAM,GAAG,IAAA,8BAAoB,EAAC,QAAQ,EAAE,mBAAU,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { BytesToHexFn, HexToBytesFn, HexToStringFn, RandomBytesFn, StringToHexFn } from './types';
2
+ export declare const bytesToHex: typeof BytesToHexFn;
3
+ export declare const hexToBytes: typeof HexToBytesFn;
4
+ export declare const hexToString: typeof HexToStringFn;
5
+ export declare const stringToHex: typeof StringToHexFn;
6
+ export declare const randomBytes: typeof RandomBytesFn;
7
+ export * from './shared';
8
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/utils/browser.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACd,MAAM,SAAS,CAAA;AAIhB,eAAO,MAAM,UAAU,EAAE,OAAO,YAK/B,CAAA;AAGD,eAAO,MAAM,UAAU,EAAE,OAAO,YAgB/B,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,OAAO,aAKhC,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,OAAO,aAEhC,CAAA;AAGD,eAAO,MAAM,WAAW,EAAE,OAAO,aAAgC,CAAA;AACjE,cAAc,UAAU,CAAA"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.randomBytes = exports.stringToHex = exports.hexToString = exports.hexToBytes = exports.bytesToHex = void 0;
18
+ const utils_1 = require("@noble/hashes/utils");
19
+ const shared_1 = require("./shared");
20
+ /* eslint-disable func-style -- Typed to ensure uniformity between node and browser implementations and docs */
21
+ const bytesToHex = (bytes) => {
22
+ const hex = (0, utils_1.bytesToHex)(bytes instanceof Uint8Array ? bytes : Uint8Array.from(bytes));
23
+ return hex.toUpperCase();
24
+ };
25
+ exports.bytesToHex = bytesToHex;
26
+ // A clone of hexToBytes from @noble/hashes without the length checks. This allows us to do our own checks.
27
+ const hexToBytes = (hex) => {
28
+ const len = hex.length;
29
+ const array = new Uint8Array(len / 2);
30
+ if (!shared_1.HEX_REGEX.test(hex)) {
31
+ throw new Error('Invalid hex string');
32
+ }
33
+ for (let i = 0; i < array.length; i++) {
34
+ const j = i * 2;
35
+ const hexByte = hex.slice(j, j + 2);
36
+ const byte = Number.parseInt(hexByte, 16);
37
+ if (Number.isNaN(byte) || byte < 0) {
38
+ throw new Error('Invalid byte sequence');
39
+ }
40
+ array[i] = byte;
41
+ }
42
+ return array;
43
+ };
44
+ exports.hexToBytes = hexToBytes;
45
+ const hexToString = (hex, encoding = 'utf8') => {
46
+ return new TextDecoder(encoding).decode((0, exports.hexToBytes)(hex));
47
+ };
48
+ exports.hexToString = hexToString;
49
+ const stringToHex = (string) => {
50
+ return (0, exports.bytesToHex)(new TextEncoder().encode(string));
51
+ };
52
+ exports.stringToHex = stringToHex;
53
+ /* eslint-enable func-style */
54
+ exports.randomBytes = utils_1.randomBytes;
55
+ __exportStar(require("./shared"), exports);
56
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/utils/browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAG4B;AAQ5B,qCAAoC;AAEpC,+GAA+G;AACxG,MAAM,UAAU,GAAwB,CAAC,KAAK,EAAE,EAAE;IACvD,MAAM,GAAG,GAAG,IAAA,kBAAe,EACzB,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAC7D,CAAA;IACD,OAAO,GAAG,CAAC,WAAW,EAAE,CAAA;AAC1B,CAAC,CAAA;AALY,QAAA,UAAU,cAKtB;AAED,2GAA2G;AACpG,MAAM,UAAU,GAAwB,CAAC,GAAG,EAAc,EAAE;IACjE,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAA;IACtB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrC,IAAI,CAAC,kBAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;KACtC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACrC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACf,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;QACnC,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;QACzC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE;YAClC,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;SACzC;QACD,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;KAChB;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAhBY,QAAA,UAAU,cAgBtB;AAEM,MAAM,WAAW,GAAyB,CAC/C,GAAW,EACX,QAAQ,GAAG,MAAM,EACT,EAAE;IACV,OAAO,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAA,kBAAU,EAAC,GAAG,CAAC,CAAC,CAAA;AAC1D,CAAC,CAAA;AALY,QAAA,WAAW,eAKvB;AAEM,MAAM,WAAW,GAAyB,CAAC,MAAc,EAAU,EAAE;IAC1E,OAAO,IAAA,kBAAU,EAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;AACrD,CAAC,CAAA;AAFY,QAAA,WAAW,eAEvB;AACD,8BAA8B;AAEjB,QAAA,WAAW,GAAyB,mBAAgB,CAAA;AACjE,2CAAwB"}
@@ -0,0 +1,9 @@
1
+ import type { BytesToHexFn, HexToBytesFn, RandomBytesFn } from './types';
2
+ import { HexToStringFn, StringToHexFn } from './types';
3
+ export declare const bytesToHex: typeof BytesToHexFn;
4
+ export declare const hexToBytes: typeof HexToBytesFn;
5
+ export declare const randomBytes: typeof RandomBytesFn;
6
+ export declare const hexToString: typeof HexToStringFn;
7
+ export declare const stringToHex: typeof StringToHexFn;
8
+ export * from './shared';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACxE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AA2DtD,eAAO,MAAM,UAAU,EAAE,OAAO,YAG/B,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,OAAO,YAK/B,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,OAAO,aAEhC,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,OAAO,aAQhC,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,OAAO,aAEhC,CAAA;AAGD,cAAc,UAAU,CAAA"}