shogun-core 6.2.0 → 6.2.2

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.
@@ -141459,7 +141459,7 @@ class ShogunCore {
141459
141459
  }
141460
141460
  }
141461
141461
  exports.ShogunCore = ShogunCore;
141462
- ShogunCore.API_VERSION = "^4.0.7";
141462
+ ShogunCore.API_VERSION = "^6.2.1";
141463
141463
  // Global declarations are handled in the original core.ts file
141464
141464
  // to avoid conflicts, we only set the window properties here
141465
141465
  if (true) {
@@ -144316,15 +144316,77 @@ const generateSignalSigningKeyPair = async () => {
144316
144316
  };
144317
144317
  exports.generateSignalSigningKeyPair = generateSignalSigningKeyPair;
144318
144318
  const exportSignalPublicKey = async (publicKey) => {
144319
- // Handle fallback keys for testing
144320
- if (publicKey &&
144321
- typeof publicKey === "object" &&
144322
- publicKey.algorithm &&
144323
- !publicKey.extractable) {
144324
- // This is a fallback key object, return a mock ArrayBuffer
144325
- return new ArrayBuffer(32);
144319
+ try {
144320
+ // Check key properties
144321
+ const algorithmName = publicKey?.algorithm?.name;
144322
+ const isExtractable = publicKey?.extractable;
144323
+ if (!isExtractable) {
144324
+ throw new Error(`Cannot export non-extractable key. Algorithm: ${algorithmName}, Type: ${publicKey?.type}`);
144325
+ }
144326
+ // For Ed25519 keys, try raw format first, fallback to spki if needed
144327
+ let exported;
144328
+ if (algorithmName === "Ed25519") {
144329
+ try {
144330
+ exported = await crypto.subtle.exportKey("raw", publicKey);
144331
+ // Validate that we got actual data (not all zeros)
144332
+ const bytes = new Uint8Array(exported);
144333
+ const isAllZeros = bytes.every((byte) => byte === 0);
144334
+ if (isAllZeros) {
144335
+ throw new Error("Export returned all zeros");
144336
+ }
144337
+ }
144338
+ catch (rawError) {
144339
+ // Try SPKI format as fallback for Ed25519
144340
+ try {
144341
+ const spki = await crypto.subtle.exportKey("spki", publicKey);
144342
+ // Extract the raw 32-byte key from SPKI format (Ed25519 public key is last 32 bytes)
144343
+ // SPKI structure: [header bytes...][32-byte public key]
144344
+ const spkiBytes = new Uint8Array(spki);
144345
+ if (spkiBytes.length < 32) {
144346
+ throw new Error(`SPKI format too short: ${spkiBytes.length} bytes`);
144347
+ }
144348
+ // Extract last 32 bytes (Ed25519 public key)
144349
+ exported = spkiBytes.slice(-32).buffer;
144350
+ }
144351
+ catch (spkiError) {
144352
+ throw new Error(`Failed to export Ed25519 key in both raw and spki formats. Raw error: ${rawError instanceof Error ? rawError.message : rawError}, SPKI error: ${spkiError instanceof Error ? spkiError.message : spkiError}`);
144353
+ }
144354
+ }
144355
+ }
144356
+ else {
144357
+ // For X25519 and other keys, use raw format
144358
+ exported = await crypto.subtle.exportKey("raw", publicKey);
144359
+ }
144360
+ // Final validation
144361
+ const finalBytes = new Uint8Array(exported);
144362
+ const isAllZeros = finalBytes.every((byte) => byte === 0);
144363
+ if (isAllZeros) {
144364
+ throw new Error(`Exported key is all zeros. Algorithm: ${algorithmName}, Size: ${exported.byteLength} bytes`);
144365
+ }
144366
+ return exported;
144367
+ }
144368
+ catch (error) {
144369
+ // If export fails, it might be a fallback/mock key
144370
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
144371
+ const algorithmName = publicKey?.algorithm?.name;
144372
+ console.error("exportSignalPublicKey failed:", errorMessage, {
144373
+ algorithm: algorithmName,
144374
+ type: publicKey?.type,
144375
+ extractable: publicKey?.extractable,
144376
+ });
144377
+ // Check if this is a fallback key object (doesn't have standard CryptoKey properties)
144378
+ // Fallback keys are just plain objects, not real CryptoKey instances
144379
+ if (publicKey &&
144380
+ typeof publicKey === "object" &&
144381
+ publicKey.algorithm &&
144382
+ (!publicKey.extractable || !(publicKey instanceof CryptoKey))) {
144383
+ // This is a fallback key object - we can't export it, so we need to generate a proper key
144384
+ // This should not happen in production - it means Ed25519 is not supported
144385
+ throw new Error(`Cannot export fallback ${algorithmName} key. ${algorithmName} is not supported in this environment. Error: ${errorMessage}`);
144386
+ }
144387
+ // Re-throw if it's not a fallback key issue
144388
+ throw error;
144326
144389
  }
144327
- return await crypto.subtle.exportKey("raw", publicKey);
144328
144390
  };
144329
144391
  exports.exportSignalPublicKey = exportSignalPublicKey;
144330
144392
  const importSignalPublicKey = async (keyBytes) => {
@@ -144442,13 +144504,30 @@ const getSignalPublicKeyBundle = async (user) => {
144442
144504
  try {
144443
144505
  console.log("Exporting identity X25519 key...");
144444
144506
  const identityKey = await (0, exports.exportSignalPublicKey)(user.identityKeyPair.publicKey);
144507
+ console.log(`✓ Identity X25519 key exported: ${identityKey.byteLength} bytes`);
144445
144508
  console.log("Exporting identity signing key...");
144509
+ const identitySigningKeyBefore = user.identitySigningKeyPair.publicKey;
144510
+ console.log("Identity signing key properties:", {
144511
+ algorithm: identitySigningKeyBefore?.algorithm?.name,
144512
+ type: identitySigningKeyBefore?.type,
144513
+ extractable: identitySigningKeyBefore?.extractable,
144514
+ });
144446
144515
  const identitySigningKey = await (0, exports.exportSignalPublicKey)(user.identitySigningKeyPair.publicKey);
144516
+ const signingKeyBytes = new Uint8Array(identitySigningKey);
144517
+ console.log(`✓ Identity signing key exported: ${identitySigningKey.byteLength} bytes, first 8 bytes:`, Array.from(signingKeyBytes.slice(0, 8)));
144518
+ const isAllZeros = signingKeyBytes.every((byte) => byte === 0);
144519
+ if (isAllZeros) {
144520
+ throw new Error("Identity signing key export returned all zeros - this should have been caught by exportSignalPublicKey");
144521
+ }
144447
144522
  console.log("Exporting signed prekey...");
144448
144523
  const signedPrekey = await (0, exports.exportSignalPublicKey)(user.signedPrekeyPair.publicKey);
144524
+ console.log(`✓ Signed prekey exported: ${signedPrekey.byteLength} bytes`);
144449
144525
  const oneTimePrekey = user.oneTimePrekeyPairs.length > 0
144450
144526
  ? await (0, exports.exportSignalPublicKey)(user.oneTimePrekeyPairs[0].publicKey)
144451
144527
  : null;
144528
+ if (oneTimePrekey) {
144529
+ console.log(`✓ One-time prekey exported: ${oneTimePrekey.byteLength} bytes`);
144530
+ }
144452
144531
  const bundle = {
144453
144532
  identityKey, // X25519 key
144454
144533
  identitySigningKey, // Ed25519 key