@tchain/tcabci-read-js-client 2.8.3 → 2.8.4
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/package.json +2 -1
- package/passKey.js +48 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tchain/tcabci-read-js-client",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.4",
|
|
4
4
|
"description": "TransferChain Fastest Read Network WebSocket Client",
|
|
5
5
|
"homepage": "https://github.com/TransferChain/tcabci-read-js-client#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"client.js",
|
|
22
22
|
"errors.js",
|
|
23
23
|
"message.js",
|
|
24
|
+
"passKey.js",
|
|
24
25
|
"transaction.js",
|
|
25
26
|
"util.js",
|
|
26
27
|
"websocket.js",
|
package/passKey.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA-512 of four concatenated lowercase UUID-v4 ASCII identifiers, matching
|
|
3
|
+
* SDK passKey defaults. Uses WebCrypto without a dependency on the SDK.
|
|
4
|
+
* Owned entropy, ASCII and digest bytes are cleared on success and failure.
|
|
5
|
+
* Immutable returned hex and runtime/native copies cannot be explicitly erased.
|
|
6
|
+
* @param {(Uint8Array) => Uint8Array} randomizer
|
|
7
|
+
* @returns {Promise<string>} 128 lowercase hex characters; not an auth credential.
|
|
8
|
+
*/
|
|
9
|
+
export async function passKey(randomizer = null) {
|
|
10
|
+
const entropy = new Uint8Array(64),
|
|
11
|
+
ascii = new Uint8Array(144)
|
|
12
|
+
let digest
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
if (!randomizer) globalThis.crypto.getRandomValues(entropy)
|
|
16
|
+
else randomizer(entropy)
|
|
17
|
+
|
|
18
|
+
let offset = 0
|
|
19
|
+
|
|
20
|
+
for (let uuid = 0; uuid < 4; uuid++) {
|
|
21
|
+
const start = uuid * 16
|
|
22
|
+
|
|
23
|
+
entropy[start + 6] = (entropy[start + 6] & 15) | 64
|
|
24
|
+
entropy[start + 8] = (entropy[start + 8] & 63) | 128
|
|
25
|
+
|
|
26
|
+
for (let index = 0; index < 16; index++) {
|
|
27
|
+
if ([4, 6, 8, 10].includes(index)) ascii[offset++] = 45
|
|
28
|
+
|
|
29
|
+
const value = entropy[start + index]
|
|
30
|
+
|
|
31
|
+
for (const nibble of [value >>> 4, value & 15])
|
|
32
|
+
ascii[offset++] = nibble < 10 ? 48 + nibble : 87 + nibble
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
digest = new Uint8Array(
|
|
37
|
+
await globalThis.crypto.subtle.digest('SHA-512', ascii)
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return Array.from(digest, (byte) =>
|
|
41
|
+
byte.toString(16).padStart(2, '0')
|
|
42
|
+
).join('')
|
|
43
|
+
} finally {
|
|
44
|
+
entropy.fill(0)
|
|
45
|
+
ascii.fill(0)
|
|
46
|
+
digest?.fill(0)
|
|
47
|
+
}
|
|
48
|
+
}
|