@bcts/uniform-resources 1.0.0-alpha.13 → 1.0.0-alpha.15
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/LICENSE +2 -2
- package/dist/index.cjs +153 -101
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +5 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +154 -103
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +154 -101
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/fountain.ts +15 -35
- package/src/multipart-decoder.ts +30 -14
- package/src/multipart-encoder.ts +6 -19
- package/src/utils.ts +7 -10
- package/src/xoshiro.ts +170 -76
package/dist/index.d.cts
CHANGED
|
@@ -409,7 +409,8 @@ declare class MultipartEncoder {
|
|
|
409
409
|
*/
|
|
410
410
|
private _encodePart;
|
|
411
411
|
/**
|
|
412
|
-
* Encodes part metadata and data
|
|
412
|
+
* Encodes part metadata and data as CBOR for bytewords encoding.
|
|
413
|
+
* Format: CBOR array [seqNum, seqLen, messageLen, checksum, data]
|
|
413
414
|
*/
|
|
414
415
|
private _encodePartData;
|
|
415
416
|
/**
|
|
@@ -463,6 +464,8 @@ declare class MultipartDecoder {
|
|
|
463
464
|
private _parsePart;
|
|
464
465
|
/**
|
|
465
466
|
* Decodes a multipart UR's fountain part data.
|
|
467
|
+
*
|
|
468
|
+
* The multipart body is a CBOR array: [seqNum, seqLen, messageLen, checksum, data]
|
|
466
469
|
*/
|
|
467
470
|
private _decodeFountainPart;
|
|
468
471
|
/**
|
|
@@ -502,7 +505,7 @@ declare function encodeBytemojisIdentifier(data: Uint8Array): string;
|
|
|
502
505
|
declare enum BytewordsStyle {
|
|
503
506
|
/** Full 4-letter words separated by spaces */
|
|
504
507
|
Standard = "standard",
|
|
505
|
-
/** Full 4-letter words
|
|
508
|
+
/** Full 4-letter words separated by hyphens (URI-safe) */
|
|
506
509
|
Uri = "uri",
|
|
507
510
|
/** First and last character only (minimal) - used by UR encoding */
|
|
508
511
|
Minimal = "minimal",
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/error.ts","../src/ur-type.ts","../src/ur.ts","../src/ur-encodable.ts","../src/ur-decodable.ts","../src/ur-codable.ts","../src/multipart-encoder.ts","../src/multipart-decoder.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;AAGa,cAAA,OAAA,SAAgB,KAAA,CAAK;EAUrB,WAAA,CAAA,OAAA,EAAmB,MAAA;AAUhC;AAUA;AAUA;AAUA;AAUa,cAlDA,kBAAA,SAA2B,OAAA,CAkDG;EAU9B,WAAA,CAAA;AAWb;AAOA;AAKA;;cAzEa,oBAAA,SAA6B,OAAA;;ACT1C;;;;AAiE0C,cD9C7B,gBAAA,SAAyB,OAAA,CC8CI;EAAgB,WAAA,CAAA;;;;AClD1D;AAgB8B,cFFjB,kBAAA,SAA2B,OAAA,CEEV;EAAc,WAAA,CAAA;;;;;AA+EhC,cFvEC,mBAAA,SAA4B,OAAA,CEuE7B;EAgBuB,WAAA,CAAA,QAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA;;;;;cF7EtB,cAAA,SAAuB,OAAA;EGzCnB,WAAA,CAAA,OAAW,EAAA,MAIpB;AAWR;;;;ACfiB,cJmDJ,SAAA,SAAkB,OAAA,CI3ChB;EAkBC,WAAA,CAAA,OAAa,EAAA,MAAA;;;;ACjB7B;AAKA;cLgDa,aAAA,SAAsB,OAAA;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/error.ts","../src/ur-type.ts","../src/ur.ts","../src/ur-encodable.ts","../src/ur-decodable.ts","../src/ur-codable.ts","../src/multipart-encoder.ts","../src/multipart-decoder.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;AAGa,cAAA,OAAA,SAAg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A,KAAA;EAeD;;;;AENhB;AAKA;;iBGooBgB,eAAA,OACR,oBACC;;AFzoBT;;;iBEmrBgB,eAAA,0BAEP,iBACN"}
|
package/dist/index.d.mts
CHANGED
|
@@ -409,7 +409,8 @@ declare class MultipartEncoder {
|
|
|
409
409
|
*/
|
|
410
410
|
private _encodePart;
|
|
411
411
|
/**
|
|
412
|
-
* Encodes part metadata and data
|
|
412
|
+
* Encodes part metadata and data as CBOR for bytewords encoding.
|
|
413
|
+
* Format: CBOR array [seqNum, seqLen, messageLen, checksum, data]
|
|
413
414
|
*/
|
|
414
415
|
private _encodePartData;
|
|
415
416
|
/**
|
|
@@ -463,6 +464,8 @@ declare class MultipartDecoder {
|
|
|
463
464
|
private _parsePart;
|
|
464
465
|
/**
|
|
465
466
|
* Decodes a multipart UR's fountain part data.
|
|
467
|
+
*
|
|
468
|
+
* The multipart body is a CBOR array: [seqNum, seqLen, messageLen, checksum, data]
|
|
466
469
|
*/
|
|
467
470
|
private _decodeFountainPart;
|
|
468
471
|
/**
|
|
@@ -502,7 +505,7 @@ declare function encodeBytemojisIdentifier(data: Uint8Array): string;
|
|
|
502
505
|
declare enum BytewordsStyle {
|
|
503
506
|
/** Full 4-letter words separated by spaces */
|
|
504
507
|
Standard = "standard",
|
|
505
|
-
/** Full 4-letter words
|
|
508
|
+
/** Full 4-letter words separated by hyphens (URI-safe) */
|
|
506
509
|
Uri = "uri",
|
|
507
510
|
/** First and last character only (minimal) - used by UR encoding */
|
|
508
511
|
Minimal = "minimal",
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/error.ts","../src/ur-type.ts","../src/ur.ts","../src/ur-encodable.ts","../src/ur-decodable.ts","../src/ur-codable.ts","../src/multipart-encoder.ts","../src/multipart-decoder.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;AAGa,cAAA,OAAA,SAAgB,KAAA,CAAK;EAUrB,WAAA,CAAA,OAAA,EAAmB,MAAA;AAUhC;AAUA;AAUA;AAUA;AAUa,cAlDA,kBAAA,SAA2B,OAAA,CAkDG;EAU9B,WAAA,CAAA;AAWb;AAOA;AAKA;;cAzEa,oBAAA,SAA6B,OAAA;;ACT1C;;;;AAiE0C,cD9C7B,gBAAA,SAAyB,OAAA,CC8CI;EAAgB,WAAA,CAAA;;;;AClD1D;AAgB8B,cFFjB,kBAAA,SAA2B,OAAA,CEEV;EAAc,WAAA,CAAA;;;;;AA+EhC,cFvEC,mBAAA,SAA4B,OAAA,CEuE7B;EAgBuB,WAAA,CAAA,QAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA;;;;;cF7EtB,cAAA,SAAuB,OAAA;EGzCnB,WAAA,CAAA,OAAW,EAAA,MAIpB;AAWR;;;;ACfiB,cJmDJ,SAAA,SAAkB,OAAA,CI3ChB;EAkBC,WAAA,CAAA,OAAa,EAAA,MAAA;;;;ACjB7B;AAKA;cLgDa,aAAA,SAAsB,OAAA;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/error.ts","../src/ur-type.ts","../src/ur.ts","../src/ur-encodable.ts","../src/ur-decodable.ts","../src/ur-codable.ts","../src/multipart-encoder.ts","../src/multipart-decoder.ts","../src/utils.ts"],"sourcesContent":[],"mappings":";;;;;;AAGa,cAAA,OAAA,SAAgB,KAAA,CAAK;EAUrB,WAAA,CAAA,OAAA,EAAmB,MAAA;AAUhC;AAUA;AAUA;AAUA;AAUa,cAlDA,kBAAA,SAA2B,OAAA,CAkDG;EAU9B,WAAA,CAAA;AAWb;AAOA;AAKA;;cAzEa,oBAAA,SAA6B,OAAA;;ACT1C;;;;AAiE0C,cD9C7B,gBAAA,SAAyB,OAAA,CC8CI;EAAgB,WAAA,CAAA;;;;AClD1D;AAgB8B,cFFjB,kBAAA,SAA2B,OAAA,CEEV;EAAc,WAAA,CAAA;;;;;AA+EhC,cFvEC,mBAAA,SAA4B,OAAA,CEuE7B;EAgBuB,WA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;;ACjBA;AAKA;;;;ACHA;;;;ECPa,QAAA,CAAA,CAAA,EAAA,MAAA;;;;ECcA,QAAA,WAiQZ;EAmBY;AAsQb;AAkBA;AAkBA;EAkEgB,QAAA,eAAe;EA4Cf;;;;;;;;;;;;;;;;ARjtBhB;AAUA;AAUA;AAUA;AAUA;AAUA;AAUA;AAUA;AAWA;AAOA;AAKA;;;;AClFA;;;AAiEiC,cMrDpB,gBAAA,CNqDoB;EAAS,QAAA,OAAA;EAAgB,QAAA,gBAAA;;;;AClD1D;;;;;EAqDY,OAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAcF;;;EA6DM,QAAA,UAAA;EAAE;;;;ACvIlB;EAegB,QAAA,mBAAa;;;;ECfZ,UAAA,CAAA,CAAA,EAAW,OAAA;EA0BZ;;;;ACjBhB;EAKgB,OAAA,CAAA,CAAA,EE2IH,EF3IG,GAAW,IAAA;;;;;;;AJtB3B;AAqCgB,cOXH,SPWG,EAAA,MAAA,EAAA;;;;;cOyQH;;AN/Rb;;AAgB4C,iBMqhB5B,yBAAA,CNrhB4B,IAAA,EMqhBI,UNrhBJ,CAAA,EAAA,MAAA;;;;AAmDlC,iBMofM,yBAAA,CNpfN,IAAA,EMofsC,UNpftC,CAAA,EAAA,MAAA;;;;AA6DQ,aMycN,cAAA;;;;ELhlBK,GAAA,GAAA,KAAA;EAeD;;;;AENhB;AAKA;;iBGooBgB,eAAA,OACR,oBACC;;AFzoBT;;;iBEmrBgB,eAAA,0BAEP,iBACN"}
|
package/dist/index.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var bctsUniformResources = (function(exports) {
|
|
1
|
+
var bctsUniformResources = (function(exports, _bcts_crypto) {
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
//#region ../dcbor/dist/index.mjs
|
|
@@ -7247,7 +7247,7 @@ var bctsUniformResources = (function(exports) {
|
|
|
7247
7247
|
let BytewordsStyle = /* @__PURE__ */ function(BytewordsStyle$1) {
|
|
7248
7248
|
/** Full 4-letter words separated by spaces */
|
|
7249
7249
|
BytewordsStyle$1["Standard"] = "standard";
|
|
7250
|
-
/** Full 4-letter words
|
|
7250
|
+
/** Full 4-letter words separated by hyphens (URI-safe) */
|
|
7251
7251
|
BytewordsStyle$1["Uri"] = "uri";
|
|
7252
7252
|
/** First and last character only (minimal) - used by UR encoding */
|
|
7253
7253
|
BytewordsStyle$1["Minimal"] = "minimal";
|
|
@@ -7323,7 +7323,7 @@ var bctsUniformResources = (function(exports) {
|
|
|
7323
7323
|
}
|
|
7324
7324
|
switch (style) {
|
|
7325
7325
|
case BytewordsStyle.Standard: return words.join(" ");
|
|
7326
|
-
case BytewordsStyle.Uri:
|
|
7326
|
+
case BytewordsStyle.Uri: return words.join("-");
|
|
7327
7327
|
case BytewordsStyle.Minimal: return words.join("");
|
|
7328
7328
|
}
|
|
7329
7329
|
}
|
|
@@ -7343,14 +7343,11 @@ var bctsUniformResources = (function(exports) {
|
|
|
7343
7343
|
});
|
|
7344
7344
|
break;
|
|
7345
7345
|
case BytewordsStyle.Uri:
|
|
7346
|
-
|
|
7347
|
-
bytes = [];
|
|
7348
|
-
for (let i = 0; i < lowercased.length; i += 4) {
|
|
7349
|
-
const word = lowercased.slice(i, i + 4);
|
|
7346
|
+
bytes = lowercased.split("-").map((word) => {
|
|
7350
7347
|
const index = BYTEWORDS_MAP.get(word);
|
|
7351
7348
|
if (index === void 0) throw new Error(`Invalid byteword: ${word}`);
|
|
7352
|
-
|
|
7353
|
-
}
|
|
7349
|
+
return index;
|
|
7350
|
+
});
|
|
7354
7351
|
break;
|
|
7355
7352
|
case BytewordsStyle.Minimal:
|
|
7356
7353
|
if (lowercased.length % 2 !== 0) throw new Error("Invalid minimal bytewords length");
|
|
@@ -7655,6 +7652,7 @@ var bctsUniformResources = (function(exports) {
|
|
|
7655
7652
|
* for deterministic fragment selection in fountain codes.
|
|
7656
7653
|
*
|
|
7657
7654
|
* Reference: https://prng.di.unimi.it/
|
|
7655
|
+
* BC-UR Reference: https://github.com/nicklockwood/fountain-codes
|
|
7658
7656
|
*/
|
|
7659
7657
|
const MAX_UINT64 = BigInt("0xffffffffffffffff");
|
|
7660
7658
|
/**
|
|
@@ -7674,21 +7672,28 @@ var bctsUniformResources = (function(exports) {
|
|
|
7674
7672
|
var Xoshiro256 = class Xoshiro256 {
|
|
7675
7673
|
s;
|
|
7676
7674
|
/**
|
|
7677
|
-
* Creates a new Xoshiro256** instance from a seed.
|
|
7675
|
+
* Creates a new Xoshiro256** instance from a 32-byte seed.
|
|
7678
7676
|
*
|
|
7679
|
-
* The seed
|
|
7680
|
-
*
|
|
7677
|
+
* The seed must be exactly 32 bytes (256 bits). The bytes are interpreted
|
|
7678
|
+
* using the BC-UR reference algorithm: each 8-byte chunk is read as
|
|
7679
|
+
* big-endian then stored as little-endian for the state.
|
|
7681
7680
|
*
|
|
7682
|
-
* @param seed - The seed bytes (
|
|
7681
|
+
* @param seed - The seed bytes (must be exactly 32 bytes)
|
|
7683
7682
|
*/
|
|
7684
7683
|
constructor(seed) {
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7684
|
+
if (seed.length !== 32) throw new Error(`Seed must be 32 bytes, got ${seed.length}`);
|
|
7685
|
+
const s = [
|
|
7686
|
+
0n,
|
|
7687
|
+
0n,
|
|
7688
|
+
0n,
|
|
7689
|
+
0n
|
|
7691
7690
|
];
|
|
7691
|
+
for (let i = 0; i < 4; i++) {
|
|
7692
|
+
let v = 0n;
|
|
7693
|
+
for (let n = 0; n < 8; n++) v = v << 8n | BigInt(seed[8 * i + n] ?? 0);
|
|
7694
|
+
s[i] = v;
|
|
7695
|
+
}
|
|
7696
|
+
this.s = s;
|
|
7692
7697
|
}
|
|
7693
7698
|
/**
|
|
7694
7699
|
* Creates a Xoshiro256** instance from raw state values.
|
|
@@ -7705,33 +7710,6 @@ var bctsUniformResources = (function(exports) {
|
|
|
7705
7710
|
return instance;
|
|
7706
7711
|
}
|
|
7707
7712
|
/**
|
|
7708
|
-
* Simple hash function for seeding.
|
|
7709
|
-
* This is a basic implementation - in production use SHA-256.
|
|
7710
|
-
*/
|
|
7711
|
-
hashSeed(seed) {
|
|
7712
|
-
const result = new Uint8Array(32);
|
|
7713
|
-
if (seed.length === 0) return result;
|
|
7714
|
-
for (let i = 0; i < 32; i++) {
|
|
7715
|
-
let hash = 0;
|
|
7716
|
-
for (const byte of seed) hash = hash * 31 + byte + i >>> 0;
|
|
7717
|
-
hash ^= hash >>> 16;
|
|
7718
|
-
hash = hash * 2246822507 >>> 0;
|
|
7719
|
-
hash ^= hash >>> 13;
|
|
7720
|
-
hash = hash * 3266489909 >>> 0;
|
|
7721
|
-
hash ^= hash >>> 16;
|
|
7722
|
-
result[i] = hash & 255;
|
|
7723
|
-
}
|
|
7724
|
-
return result;
|
|
7725
|
-
}
|
|
7726
|
-
/**
|
|
7727
|
-
* Converts 8 bytes to a 64-bit BigInt (little-endian).
|
|
7728
|
-
*/
|
|
7729
|
-
bytesToBigInt(bytes) {
|
|
7730
|
-
let result = 0n;
|
|
7731
|
-
for (let i = 7; i >= 0; i--) result = result << 8n | BigInt(bytes[i] ?? 0);
|
|
7732
|
-
return result;
|
|
7733
|
-
}
|
|
7734
|
-
/**
|
|
7735
7713
|
* Generates the next 64-bit random value.
|
|
7736
7714
|
*/
|
|
7737
7715
|
next() {
|
|
@@ -7747,17 +7725,19 @@ var bctsUniformResources = (function(exports) {
|
|
|
7747
7725
|
}
|
|
7748
7726
|
/**
|
|
7749
7727
|
* Generates a random double in [0, 1).
|
|
7728
|
+
* Matches BC-UR reference: self.next() as f64 / (u64::MAX as f64 + 1.0)
|
|
7750
7729
|
*/
|
|
7751
7730
|
nextDouble() {
|
|
7752
7731
|
const value = this.next();
|
|
7753
|
-
return Number(value
|
|
7732
|
+
return Number(value) / 0x10000000000000000;
|
|
7754
7733
|
}
|
|
7755
7734
|
/**
|
|
7756
|
-
* Generates a random integer in [low, high).
|
|
7735
|
+
* Generates a random integer in [low, high] (inclusive).
|
|
7736
|
+
* Matches BC-UR reference: (self.next_double() * ((high - low + 1) as f64)) as u64 + low
|
|
7757
7737
|
*/
|
|
7758
7738
|
nextInt(low, high) {
|
|
7759
|
-
const range$1 = high - low;
|
|
7760
|
-
return
|
|
7739
|
+
const range$1 = high - low + 1;
|
|
7740
|
+
return Math.floor(this.nextDouble() * range$1) + low;
|
|
7761
7741
|
}
|
|
7762
7742
|
/**
|
|
7763
7743
|
* Generates a random byte [0, 255].
|
|
@@ -7773,24 +7753,102 @@ var bctsUniformResources = (function(exports) {
|
|
|
7773
7753
|
for (let i = 0; i < count; i++) result[i] = this.nextByte();
|
|
7774
7754
|
return result;
|
|
7775
7755
|
}
|
|
7756
|
+
/**
|
|
7757
|
+
* Shuffles items by repeatedly picking random indices.
|
|
7758
|
+
* Matches BC-UR reference implementation.
|
|
7759
|
+
*/
|
|
7760
|
+
shuffled(items) {
|
|
7761
|
+
const source = [...items];
|
|
7762
|
+
const shuffled = [];
|
|
7763
|
+
while (source.length > 0) {
|
|
7764
|
+
const index = this.nextInt(0, source.length - 1);
|
|
7765
|
+
const item = source.splice(index, 1)[0];
|
|
7766
|
+
if (item !== void 0) shuffled.push(item);
|
|
7767
|
+
}
|
|
7768
|
+
return shuffled;
|
|
7769
|
+
}
|
|
7770
|
+
/**
|
|
7771
|
+
* Chooses the degree (number of fragments to mix) using a weighted sampler.
|
|
7772
|
+
* Uses the robust soliton distribution with weights [1/1, 1/2, 1/3, ..., 1/n].
|
|
7773
|
+
* Matches BC-UR reference implementation.
|
|
7774
|
+
*/
|
|
7775
|
+
chooseDegree(seqLen) {
|
|
7776
|
+
const weights = [];
|
|
7777
|
+
for (let i = 1; i <= seqLen; i++) weights.push(1 / i);
|
|
7778
|
+
return new WeightedSampler(weights).next(this) + 1;
|
|
7779
|
+
}
|
|
7780
|
+
};
|
|
7781
|
+
/**
|
|
7782
|
+
* Weighted sampler using Vose's alias method.
|
|
7783
|
+
* Allows O(1) sampling from a discrete probability distribution.
|
|
7784
|
+
*/
|
|
7785
|
+
var WeightedSampler = class {
|
|
7786
|
+
aliases;
|
|
7787
|
+
probs;
|
|
7788
|
+
constructor(weights) {
|
|
7789
|
+
const n = weights.length;
|
|
7790
|
+
if (n === 0) throw new Error("Weights array cannot be empty");
|
|
7791
|
+
const sum = weights.reduce((a, b) => a + b, 0);
|
|
7792
|
+
if (sum <= 0) throw new Error("Weights must sum to a positive value");
|
|
7793
|
+
const normalized = weights.map((w) => w * n / sum);
|
|
7794
|
+
this.aliases = Array.from({ length: n }).fill(0);
|
|
7795
|
+
this.probs = Array.from({ length: n }).fill(0);
|
|
7796
|
+
const small = [];
|
|
7797
|
+
const large = [];
|
|
7798
|
+
for (let i = n - 1; i >= 0; i--) if (normalized[i] < 1) small.push(i);
|
|
7799
|
+
else large.push(i);
|
|
7800
|
+
while (small.length > 0 && large.length > 0) {
|
|
7801
|
+
const a = small.pop();
|
|
7802
|
+
const g = large.pop();
|
|
7803
|
+
if (a === void 0 || g === void 0) break;
|
|
7804
|
+
this.probs[a] = normalized[a] ?? 0;
|
|
7805
|
+
this.aliases[a] = g;
|
|
7806
|
+
normalized[g] = (normalized[g] ?? 0) + (normalized[a] ?? 0) - 1;
|
|
7807
|
+
if (normalized[g] !== void 0 && normalized[g] < 1) small.push(g);
|
|
7808
|
+
else large.push(g);
|
|
7809
|
+
}
|
|
7810
|
+
while (large.length > 0) {
|
|
7811
|
+
const g = large.pop();
|
|
7812
|
+
if (g === void 0) break;
|
|
7813
|
+
this.probs[g] = 1;
|
|
7814
|
+
}
|
|
7815
|
+
while (small.length > 0) {
|
|
7816
|
+
const a = small.pop();
|
|
7817
|
+
if (a === void 0) break;
|
|
7818
|
+
this.probs[a] = 1;
|
|
7819
|
+
}
|
|
7820
|
+
}
|
|
7821
|
+
/**
|
|
7822
|
+
* Sample from the distribution.
|
|
7823
|
+
*/
|
|
7824
|
+
next(rng) {
|
|
7825
|
+
const r1 = rng.nextDouble();
|
|
7826
|
+
const r2 = rng.nextDouble();
|
|
7827
|
+
const n = this.probs.length;
|
|
7828
|
+
const i = Math.floor(n * r1);
|
|
7829
|
+
if (r2 < this.probs[i]) return i;
|
|
7830
|
+
else return this.aliases[i];
|
|
7831
|
+
}
|
|
7776
7832
|
};
|
|
7777
7833
|
/**
|
|
7778
|
-
* Creates a
|
|
7834
|
+
* Creates a Xoshiro256 PRNG instance from message checksum and sequence number.
|
|
7835
|
+
*
|
|
7836
|
+
* This creates an 8-byte seed by concatenating seqNum and checksum (both in
|
|
7837
|
+
* big-endian), then hashes it with SHA-256 to get the 32-byte seed for Xoshiro.
|
|
7779
7838
|
*
|
|
7780
|
-
* This
|
|
7781
|
-
* for a given message and part number.
|
|
7839
|
+
* This matches the BC-UR reference implementation.
|
|
7782
7840
|
*/
|
|
7783
7841
|
function createSeed(checksum, seqNum) {
|
|
7784
|
-
const
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
return
|
|
7842
|
+
const seed8 = new Uint8Array(8);
|
|
7843
|
+
seed8[0] = seqNum >>> 24 & 255;
|
|
7844
|
+
seed8[1] = seqNum >>> 16 & 255;
|
|
7845
|
+
seed8[2] = seqNum >>> 8 & 255;
|
|
7846
|
+
seed8[3] = seqNum & 255;
|
|
7847
|
+
seed8[4] = checksum >>> 24 & 255;
|
|
7848
|
+
seed8[5] = checksum >>> 16 & 255;
|
|
7849
|
+
seed8[6] = checksum >>> 8 & 255;
|
|
7850
|
+
seed8[7] = checksum & 255;
|
|
7851
|
+
return (0, _bcts_crypto.sha256)(seed8);
|
|
7794
7852
|
}
|
|
7795
7853
|
|
|
7796
7854
|
//#endregion
|
|
@@ -7837,6 +7895,11 @@ var bctsUniformResources = (function(exports) {
|
|
|
7837
7895
|
* This uses a seeded Xoshiro256** PRNG to deterministically select fragments,
|
|
7838
7896
|
* ensuring encoder and decoder agree without explicit coordination.
|
|
7839
7897
|
*
|
|
7898
|
+
* The algorithm matches the BC-UR reference implementation:
|
|
7899
|
+
* 1. For pure parts (seqNum <= seqLen), return single fragment index
|
|
7900
|
+
* 2. For mixed parts, use weighted sampling to choose degree
|
|
7901
|
+
* 3. Shuffle all indices and take the first 'degree' indices
|
|
7902
|
+
*
|
|
7840
7903
|
* @param seqNum - The sequence number (1-based)
|
|
7841
7904
|
* @param seqLen - Total number of pure fragments
|
|
7842
7905
|
* @param checksum - CRC32 checksum of the message
|
|
@@ -7845,26 +7908,10 @@ var bctsUniformResources = (function(exports) {
|
|
|
7845
7908
|
function chooseFragments(seqNum, seqLen, checksum) {
|
|
7846
7909
|
if (seqNum <= seqLen) return [seqNum - 1];
|
|
7847
7910
|
const rng = new Xoshiro256(createSeed(checksum, seqNum));
|
|
7848
|
-
const degree = chooseDegree(
|
|
7849
|
-
const
|
|
7850
|
-
|
|
7851
|
-
|
|
7852
|
-
indices.add(index);
|
|
7853
|
-
}
|
|
7854
|
-
return Array.from(indices).sort((a, b) => a - b);
|
|
7855
|
-
}
|
|
7856
|
-
/**
|
|
7857
|
-
* Chooses the degree (number of fragments to mix) using a simplified
|
|
7858
|
-
* robust soliton distribution.
|
|
7859
|
-
*
|
|
7860
|
-
* This ensures good coverage of fragments for efficient decoding.
|
|
7861
|
-
*/
|
|
7862
|
-
function chooseDegree(rng, seqLen) {
|
|
7863
|
-
const r = rng.nextDouble();
|
|
7864
|
-
if (r < .5) return 1;
|
|
7865
|
-
else if (r < .75) return 2;
|
|
7866
|
-
else if (r < .9) return Math.min(3, seqLen);
|
|
7867
|
-
else return Math.min(rng.nextInt(4, seqLen + 1), seqLen);
|
|
7911
|
+
const degree = rng.chooseDegree(seqLen);
|
|
7912
|
+
const allIndices = [];
|
|
7913
|
+
for (let i = 0; i < seqLen; i++) allIndices.push(i);
|
|
7914
|
+
return rng.shuffled(allIndices).slice(0, degree);
|
|
7868
7915
|
}
|
|
7869
7916
|
/**
|
|
7870
7917
|
* Mixes the selected fragments using XOR.
|
|
@@ -8131,20 +8178,17 @@ var bctsUniformResources = (function(exports) {
|
|
|
8131
8178
|
return `ur:${this._ur.urTypeStr()}/${part.seqNum}-${part.seqLen}/${encoded}`;
|
|
8132
8179
|
}
|
|
8133
8180
|
/**
|
|
8134
|
-
* Encodes part metadata and data
|
|
8181
|
+
* Encodes part metadata and data as CBOR for bytewords encoding.
|
|
8182
|
+
* Format: CBOR array [seqNum, seqLen, messageLen, checksum, data]
|
|
8135
8183
|
*/
|
|
8136
8184
|
_encodePartData(part) {
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
result[6] = part.checksum >>> 8 & 255;
|
|
8145
|
-
result[7] = part.checksum & 255;
|
|
8146
|
-
result.set(part.data, 8);
|
|
8147
|
-
return result;
|
|
8185
|
+
return cbor([
|
|
8186
|
+
part.seqNum,
|
|
8187
|
+
part.seqLen,
|
|
8188
|
+
part.messageLen,
|
|
8189
|
+
part.checksum,
|
|
8190
|
+
part.data
|
|
8191
|
+
]).toData();
|
|
8148
8192
|
}
|
|
8149
8193
|
/**
|
|
8150
8194
|
* Gets the current part index.
|
|
@@ -8242,16 +8286,23 @@ var bctsUniformResources = (function(exports) {
|
|
|
8242
8286
|
}
|
|
8243
8287
|
/**
|
|
8244
8288
|
* Decodes a multipart UR's fountain part data.
|
|
8289
|
+
*
|
|
8290
|
+
* The multipart body is a CBOR array: [seqNum, seqLen, messageLen, checksum, data]
|
|
8245
8291
|
*/
|
|
8246
8292
|
_decodeFountainPart(partInfo) {
|
|
8247
|
-
const
|
|
8248
|
-
if (
|
|
8249
|
-
const
|
|
8250
|
-
|
|
8251
|
-
const
|
|
8293
|
+
const decoded = decodeCbor(decodeBytewords(partInfo.encodedData, BytewordsStyle.Minimal));
|
|
8294
|
+
if (decoded.type !== MajorType.Array) throw new URError("Invalid multipart data: expected CBOR array");
|
|
8295
|
+
const items = decoded.value;
|
|
8296
|
+
if (items.length !== 5) throw new URError(`Invalid multipart data: expected 5 elements, got ${items.length}`);
|
|
8297
|
+
const seqNum = Number(items[0].value);
|
|
8298
|
+
const seqLen = Number(items[1].value);
|
|
8299
|
+
const messageLen = Number(items[2].value);
|
|
8300
|
+
const checksum = Number(items[3].value);
|
|
8301
|
+
const data = items[4].value;
|
|
8302
|
+
if (seqNum !== partInfo.seqNum || seqLen !== partInfo.seqLen) throw new URError(`Multipart metadata mismatch: URL says ${partInfo.seqNum}-${partInfo.seqLen}, CBOR says ${seqNum}-${seqLen}`);
|
|
8252
8303
|
return {
|
|
8253
|
-
seqNum
|
|
8254
|
-
seqLen
|
|
8304
|
+
seqNum,
|
|
8305
|
+
seqLen,
|
|
8255
8306
|
messageLen,
|
|
8256
8307
|
checksum,
|
|
8257
8308
|
data
|
|
@@ -8299,5 +8350,5 @@ exports.isURCodable = isURCodable;
|
|
|
8299
8350
|
exports.isURDecodable = isURDecodable;
|
|
8300
8351
|
exports.isUREncodable = isUREncodable;
|
|
8301
8352
|
return exports;
|
|
8302
|
-
})({});
|
|
8353
|
+
})({}, bctsCrypto);
|
|
8303
8354
|
//# sourceMappingURL=index.iife.js.map
|