Skip to content

Commit 13506aa

Browse files
authored
Merge pull request #412 from bsv-blockchain/fix/tob-10
TOB 10
2 parents 6048ed2 + 89d369d commit 13506aa

File tree

8 files changed

+602
-304
lines changed

8 files changed

+602
-304
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. The format
55
## Table of Contents
66

77
- [Unreleased](#unreleased)
8+
- [1.9.28 - 2025-12-11](#1928---2025-12-11)
89
- [1.9.27 - 2025-12-11](#1927---2025-12-11)
910
- [1.9.26 - 2025-12-10](#1926---2025-12-10)
1011
- [1.9.25 - 2025-12-09](#1925---2025-12-09)
@@ -200,6 +201,20 @@ All notable changes to this project will be documented in this file. The format
200201

201202
---
202203

204+
## [1.9.28] - 2025-12-11
205+
206+
### Added
207+
- Add getBytes64 helper for 64-bit length fields.
208+
- Added long ciphertext test case.
209+
210+
### Changed
211+
- Changed AESGCM to use Uint8Arrays instead of number[] for all inputs and outputs for optimization.
212+
213+
### Fixed
214+
- Use 64-bit length encoding for GHASH inputs.
215+
216+
---
217+
203218
## [1.9.27] - 2025-12-11
204219

205220
### Fixed

docs/reference/primitives.md

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,7 @@ export default class Point extends BasePoint {
17561756
x: BigNumber | null;
17571757
y: BigNumber | null;
17581758
inf: boolean;
1759+
static _assertOnCurve(p: Point): Point
17591760
static fromDER(bytes: number[]): Point
17601761
static fromString(str: string): Point
17611762
static fromX(x: BigNumber | number | number[] | string, odd: boolean): Point
@@ -5031,9 +5032,9 @@ encoding, and changing it would render previously encrypted data
50315032
undecryptable by newer versions of the library.
50325033

50335034
```ts
5034-
export function AESGCM(plainText: number[], initializationVector: number[], key: number[]): {
5035-
result: number[];
5036-
authenticationTag: number[];
5035+
export function AESGCM(plainText: Bytes, initializationVector: Bytes, key: Bytes): {
5036+
result: Bytes;
5037+
authenticationTag: Bytes;
50375038
}
50385039
```
50395040

@@ -5043,7 +5044,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
50435044
### Function: AESGCMDecrypt
50445045

50455046
```ts
5046-
export function AESGCMDecrypt(cipherText: number[], initializationVector: number[], authenticationTag: number[], key: number[]): number[] | null
5047+
export function AESGCMDecrypt(cipherText: Bytes, initializationVector: Bytes, authenticationTag: Bytes, key: Bytes): Bytes | null
50475048
```
50485049

50495050
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
@@ -5070,7 +5071,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
50705071
### Function: ghash
50715072

50725073
```ts
5073-
export function ghash(input: number[], hashSubKey: number[]): number[]
5074+
export function ghash(input: Bytes, hashSubKey: Bytes): Bytes
50745075
```
50755076

50765077
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
@@ -5299,24 +5300,24 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
52995300
53005301
| | | |
53015302
| --- | --- | --- |
5302-
| [BI_EIGHT](#variable-bi_eight) | [biModSqrt](#variable-bimodsqrt) | [multiply](#variable-multiply) |
5303-
| [BI_FOUR](#variable-bi_four) | [biModSub](#variable-bimodsub) | [rightShift](#variable-rightshift) |
5304-
| [BI_ONE](#variable-bi_one) | [checkBit](#variable-checkbit) | [ripemd160](#variable-ripemd160) |
5305-
| [BI_THREE](#variable-bi_three) | [encode](#variable-encode) | [scalarMultiplyWNAF](#variable-scalarmultiplywnaf) |
5306-
| [BI_TWO](#variable-bi_two) | [exclusiveOR](#variable-exclusiveor) | [sha1](#variable-sha1) |
5307-
| [BI_ZERO](#variable-bi_zero) | [fromBase58](#variable-frombase58) | [sha256](#variable-sha256) |
5308-
| [GX_BIGINT](#variable-gx_bigint) | [fromBase58Check](#variable-frombase58check) | [sha256hmac](#variable-sha256hmac) |
5309-
| [GY_BIGINT](#variable-gy_bigint) | [getBytes](#variable-getbytes) | [sha512](#variable-sha512) |
5310-
| [MASK_256](#variable-mask_256) | [hash160](#variable-hash160) | [sha512hmac](#variable-sha512hmac) |
5311-
| [N_BIGINT](#variable-n_bigint) | [hash256](#variable-hash256) | [sign](#variable-sign) |
5312-
| [P_BIGINT](#variable-p_bigint) | [incrementLeastSignificantThirtyTwoBits](#variable-incrementleastsignificantthirtytwobits) | [toArray](#variable-toarray) |
5313-
| [P_PLUS1_DIV4](#variable-p_plus1_div4) | [jpAdd](#variable-jpadd) | [toBase58](#variable-tobase58) |
5314-
| [biMod](#variable-bimod) | [jpDouble](#variable-jpdouble) | [toBase58Check](#variable-tobase58check) |
5315-
| [biModAdd](#variable-bimodadd) | [jpNeg](#variable-jpneg) | [toHex](#variable-tohex) |
5316-
| [biModInv](#variable-bimodinv) | [minimallyEncode](#variable-minimallyencode) | [toUTF8](#variable-toutf8) |
5317-
| [biModMul](#variable-bimodmul) | [modInvN](#variable-modinvn) | [verify](#variable-verify) |
5318-
| [biModPow](#variable-bimodpow) | [modMulN](#variable-modmuln) | [zero2](#variable-zero2) |
5319-
| [biModSqr](#variable-bimodsqr) | [modN](#variable-modn) | |
5303+
| [BI_EIGHT](#variable-bi_eight) | [biModSqrt](#variable-bimodsqrt) | [modN](#variable-modn) |
5304+
| [BI_FOUR](#variable-bi_four) | [biModSub](#variable-bimodsub) | [multiply](#variable-multiply) |
5305+
| [BI_ONE](#variable-bi_one) | [checkBit](#variable-checkbit) | [rightShift](#variable-rightshift) |
5306+
| [BI_THREE](#variable-bi_three) | [encode](#variable-encode) | [ripemd160](#variable-ripemd160) |
5307+
| [BI_TWO](#variable-bi_two) | [exclusiveOR](#variable-exclusiveor) | [scalarMultiplyWNAF](#variable-scalarmultiplywnaf) |
5308+
| [BI_ZERO](#variable-bi_zero) | [fromBase58](#variable-frombase58) | [sha1](#variable-sha1) |
5309+
| [GX_BIGINT](#variable-gx_bigint) | [fromBase58Check](#variable-frombase58check) | [sha256](#variable-sha256) |
5310+
| [GY_BIGINT](#variable-gy_bigint) | [getBytes](#variable-getbytes) | [sha256hmac](#variable-sha256hmac) |
5311+
| [MASK_256](#variable-mask_256) | [getBytes64](#variable-getbytes64) | [sha512](#variable-sha512) |
5312+
| [N_BIGINT](#variable-n_bigint) | [hash160](#variable-hash160) | [sha512hmac](#variable-sha512hmac) |
5313+
| [P_BIGINT](#variable-p_bigint) | [hash256](#variable-hash256) | [sign](#variable-sign) |
5314+
| [P_PLUS1_DIV4](#variable-p_plus1_div4) | [incrementLeastSignificantThirtyTwoBits](#variable-incrementleastsignificantthirtytwobits) | [toArray](#variable-toarray) |
5315+
| [biMod](#variable-bimod) | [jpAdd](#variable-jpadd) | [toBase58](#variable-tobase58) |
5316+
| [biModAdd](#variable-bimodadd) | [jpDouble](#variable-jpdouble) | [toBase58Check](#variable-tobase58check) |
5317+
| [biModInv](#variable-bimodinv) | [jpNeg](#variable-jpneg) | [toHex](#variable-tohex) |
5318+
| [biModMul](#variable-bimodmul) | [minimallyEncode](#variable-minimallyencode) | [toUTF8](#variable-toutf8) |
5319+
| [biModPow](#variable-bimodpow) | [modInvN](#variable-modinvn) | [verify](#variable-verify) |
5320+
| [biModSqr](#variable-bimodsqr) | [modMulN](#variable-modmuln) | [zero2](#variable-zero2) |
53205321
53215322
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
53225323
@@ -5491,20 +5492,20 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
54915492
54925493
```ts
54935494
biModPow = (base: bigint, exp: bigint): bigint => {
5494-
let result = BI_ONE;
5495+
let result = 1n;
54955496
base = biMod(base);
5496-
let e = exp;
5497-
while (e > BI_ZERO) {
5498-
if ((e & BI_ONE) === BI_ONE)
5497+
while (exp > 0n) {
5498+
if ((exp & 1n) !== 0n) {
54995499
result = biModMul(result, base);
5500+
}
55005501
base = biModMul(base, base);
5501-
e >>= BI_ONE;
5502+
exp >>= 1n;
55025503
}
55035504
return result;
55045505
}
55055506
```
55065507
5507-
See also: [BI_ONE](./primitives.md#variable-bi_one), [BI_ZERO](./primitives.md#variable-bi_zero), [biMod](./primitives.md#variable-bimod), [biModMul](./primitives.md#variable-bimodmul)
5508+
See also: [biMod](./primitives.md#variable-bimod), [biModMul](./primitives.md#variable-bimodmul)
55085509
55095510
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
55105511
@@ -5525,7 +5526,10 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
55255526
```ts
55265527
biModSqrt = (a: bigint): bigint | null => {
55275528
const r = biModPow(a, P_PLUS1_DIV4);
5528-
return biModMul(r, r) === biMod(a) ? r : null;
5529+
if (biModMul(r, r) !== biMod(a)) {
5530+
return null;
5531+
}
5532+
return r;
55295533
}
55305534
```
55315535
@@ -5579,11 +5583,11 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
55795583
### Variable: exclusiveOR
55805584
55815585
```ts
5582-
exclusiveOR = function (block0: number[], block1: number[]): number[] {
5586+
exclusiveOR = function (block0: Bytes, block1: Bytes): Bytes {
55835587
const len = block0.length;
5584-
const result = new Array(len);
5588+
const result = new Uint8Array(len);
55855589
for (let i = 0; i < len; i++) {
5586-
result[i] = block0[i] ^ block1[i];
5590+
result[i] = block0[i] ^ (block1[i] ?? 0);
55875591
}
55885592
return result;
55895593
}
@@ -5673,6 +5677,31 @@ getBytes = function (numericValue: number): number[] {
56735677
56745678
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
56755679
5680+
---
5681+
### Variable: getBytes64
5682+
5683+
```ts
5684+
getBytes64 = function (numericValue: number): number[] {
5685+
if (numericValue < 0 || numericValue > Number.MAX_SAFE_INTEGER) {
5686+
throw new Error("getBytes64: value out of range");
5687+
}
5688+
const hi = Math.floor(numericValue / 4294967296);
5689+
const lo = numericValue >>> 0;
5690+
return [
5691+
(hi >>> 24) & 255,
5692+
(hi >>> 16) & 255,
5693+
(hi >>> 8) & 255,
5694+
hi & 255,
5695+
(lo >>> 24) & 255,
5696+
(lo >>> 16) & 255,
5697+
(lo >>> 8) & 255,
5698+
lo & 255
5699+
];
5700+
}
5701+
```
5702+
5703+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Enums](#enums), [Variables](#variables)
5704+
56765705
---
56775706
### Variable: hash160
56785707
@@ -5705,15 +5734,11 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
57055734
### Variable: incrementLeastSignificantThirtyTwoBits
57065735
57075736
```ts
5708-
incrementLeastSignificantThirtyTwoBits = function (block: number[]): number[] {
5709-
let i;
5737+
incrementLeastSignificantThirtyTwoBits = function (block: Bytes): Bytes {
57105738
const result = block.slice();
5711-
for (i = 15; i !== 11; i--) {
5712-
result[i] = result[i] + 1;
5713-
if (result[i] === 256) {
5714-
result[i] = 0;
5715-
}
5716-
else {
5739+
for (let i = 15; i !== 11; i--) {
5740+
result[i] = (result[i] + 1) & 255;
5741+
if (result[i] !== 0) {
57175742
break;
57185743
}
57195744
}
@@ -5885,7 +5910,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
58855910
### Variable: multiply
58865911
58875912
```ts
5888-
multiply = function (block0: number[], block1: number[]): number[] {
5913+
multiply = function (block0: Bytes, block1: Bytes): Bytes {
58895914
const v = block1.slice();
58905915
const z = createZeroBlock(16);
58915916
for (let i = 0; i < 16; i++) {
@@ -5914,11 +5939,10 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
59145939
### Variable: rightShift
59155940
59165941
```ts
5917-
rightShift = function (block: number[]): number[] {
5918-
let i: number;
5942+
rightShift = function (block: Bytes): Bytes {
59195943
let carry = 0;
59205944
let oldCarry = 0;
5921-
for (i = 0; i < block.length; i++) {
5945+
for (let i = 0; i < block.length; i++) {
59225946
oldCarry = carry;
59235947
carry = block[i] & 1;
59245948
block[i] = block[i] >> 1;

0 commit comments

Comments
 (0)