did-beta-bch 3.1.0 → 3.1.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/bip47.js +16 -7
- package/dist/verify.js +2 -0
- package/package.json +1 -1
package/dist/bip47.js
CHANGED
|
@@ -32,10 +32,14 @@ function base58Decode(s) {
|
|
|
32
32
|
throw new Error(`Invalid Base58 character: ${c}`);
|
|
33
33
|
n = n * 58n + BigInt(d);
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
// Compute minimum byte length needed to represent n
|
|
36
|
+
let byteLen = 0;
|
|
37
|
+
let tmp = n;
|
|
38
|
+
while (tmp > 0n) {
|
|
39
|
+
byteLen++;
|
|
40
|
+
tmp >>= 8n;
|
|
41
|
+
}
|
|
42
|
+
// Count leading '1's (each = a leading zero byte)
|
|
39
43
|
let leading = 0;
|
|
40
44
|
for (const c of s) {
|
|
41
45
|
if (c === "1")
|
|
@@ -43,9 +47,14 @@ function base58Decode(s) {
|
|
|
43
47
|
else
|
|
44
48
|
break;
|
|
45
49
|
}
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
const totalLen = leading + byteLen;
|
|
51
|
+
if (totalLen !== PC_TOTAL_BYTES)
|
|
52
|
+
throw new Error(`Invalid payment code length: ${totalLen}`);
|
|
53
|
+
const hex = n.toString(16).padStart(byteLen * 2, "0");
|
|
54
|
+
const bytes = new Uint8Array(PC_TOTAL_BYTES);
|
|
55
|
+
for (let i = 0; i < byteLen; i++)
|
|
56
|
+
bytes[leading + i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
57
|
+
return bytes;
|
|
49
58
|
}
|
|
50
59
|
async function sha256Once(data) {
|
|
51
60
|
if (typeof crypto !== "undefined" && crypto.subtle)
|
package/dist/verify.js
CHANGED
|
@@ -8,6 +8,8 @@ import { BCH_PROOF_FORMAT, normalizeBchMessageSignature, } from "./signing.js";
|
|
|
8
8
|
export const NOSTR_CHALLENGE_KIND = 27235;
|
|
9
9
|
/** Encode n as a Bitcoin CompactSize integer. */
|
|
10
10
|
export function encodeBitcoinCompactSize(n) {
|
|
11
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
12
|
+
throw new RangeError("CompactSize value must be a non-negative safe integer");
|
|
11
13
|
if (n < 0xfd)
|
|
12
14
|
return new Uint8Array([n]);
|
|
13
15
|
const value = BigInt(n);
|