@haex-space/vault-sdk 2.5.80 → 2.5.84

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/index.d.mts CHANGED
@@ -532,6 +532,78 @@ declare function decryptCrdtData<T = object>(encryptedData: string, nonce: strin
532
532
  declare function arrayBufferToBase64(buffer: ArrayBuffer | Uint8Array): string;
533
533
  declare function base64ToArrayBuffer(base64: string): Uint8Array;
534
534
 
535
+ /**
536
+ * Crypto utilities for WebAuthn/Passkey operations
537
+ * Implements ECDSA P-256 (ES256) key generation and signing
538
+ *
539
+ * Used for:
540
+ * - Generating passkey key pairs during WebAuthn registration
541
+ * - Signing authentication challenges during WebAuthn authentication
542
+ * - Exporting/importing keys for storage
543
+ *
544
+ * Browser-compatible using the Web Crypto API
545
+ */
546
+
547
+ declare const COSE_ALGORITHM: {
548
+ readonly ES256: -7;
549
+ readonly ES384: -35;
550
+ readonly ES512: -36;
551
+ readonly EdDSA: -8;
552
+ readonly RS256: -257;
553
+ };
554
+ type CoseAlgorithm = (typeof COSE_ALGORITHM)[keyof typeof COSE_ALGORITHM];
555
+ interface PasskeyKeyPair {
556
+ publicKey: CryptoKey;
557
+ privateKey: CryptoKey;
558
+ }
559
+ interface ExportedPasskeyKeyPair {
560
+ publicKeyBase64: string;
561
+ privateKeyBase64: string;
562
+ publicKeyCoseBase64: string;
563
+ }
564
+ /**
565
+ * Generates a new ECDSA P-256 key pair for passkey operations
566
+ */
567
+ declare function generatePasskeyPairAsync(): Promise<PasskeyKeyPair>;
568
+ /**
569
+ * Exports the public key in SPKI format (Base64)
570
+ */
571
+ declare function exportPublicKeyAsync(publicKey: CryptoKey): Promise<string>;
572
+ /**
573
+ * Exports the private key in PKCS8 format (Base64)
574
+ */
575
+ declare function exportPrivateKeyAsync(privateKey: CryptoKey): Promise<string>;
576
+ /**
577
+ * Exports the public key in raw format and converts to COSE key format
578
+ * Required for WebAuthn attestation response
579
+ */
580
+ declare function exportPublicKeyCoseAsync(publicKey: CryptoKey): Promise<string>;
581
+ /**
582
+ * Imports a private key from PKCS8 format (Base64)
583
+ */
584
+ declare function importPrivateKeyAsync(privateKeyBase64: string): Promise<CryptoKey>;
585
+ /**
586
+ * Imports a public key from SPKI format (Base64)
587
+ */
588
+ declare function importPublicKeyAsync(publicKeyBase64: string): Promise<CryptoKey>;
589
+ /**
590
+ * Signs data with a passkey private key using ECDSA with SHA-256
591
+ * Returns the signature in DER format (as used by WebAuthn)
592
+ */
593
+ declare function signWithPasskeyAsync(privateKey: CryptoKey, data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>;
594
+ /**
595
+ * Verifies a signature with a passkey public key
596
+ */
597
+ declare function verifyWithPasskeyAsync(publicKey: CryptoKey, signature: ArrayBuffer | Uint8Array, data: ArrayBuffer | Uint8Array): Promise<boolean>;
598
+ /**
599
+ * Generates a random credential ID (16 bytes)
600
+ */
601
+ declare function generateCredentialId(): Uint8Array;
602
+ /**
603
+ * Exports a full key pair for storage
604
+ */
605
+ declare function exportKeyPairAsync(keyPair: PasskeyKeyPair): Promise<ExportedPasskeyKeyPair>;
606
+
535
607
  declare function createHaexVaultSdk(config?: HaexHubConfig): HaexVaultSdk;
536
608
 
537
- export { ExtensionManifest, HAEXSPACE_MESSAGE_TYPES, HaexHubConfig, HaexVaultSdk, type HaexspaceMessageType, TAURI_COMMANDS, type TauriCommand, type VerifyResult, type ZipFileEntry, arrayBufferToBase64, base64ToArrayBuffer, createHaexVaultSdk, decryptCrdtData, decryptString, decryptVaultKey, decryptVaultName, deriveKeyFromPassword, encryptCrdtData, encryptString, encryptVaultKey, generateVaultKey, hexToBytes, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, sortObjectKeysRecursively, unwrapKey, verifyExtensionSignature, wrapKey };
609
+ export { COSE_ALGORITHM, type CoseAlgorithm, type ExportedPasskeyKeyPair, ExtensionManifest, HAEXSPACE_MESSAGE_TYPES, HaexHubConfig, HaexVaultSdk, type HaexspaceMessageType, type PasskeyKeyPair, TAURI_COMMANDS, type TauriCommand, type VerifyResult, type ZipFileEntry, arrayBufferToBase64, base64ToArrayBuffer, createHaexVaultSdk, decryptCrdtData, decryptString, decryptVaultKey, decryptVaultName, deriveKeyFromPassword, encryptCrdtData, encryptString, encryptVaultKey, exportKeyPairAsync, exportPrivateKeyAsync, exportPublicKeyAsync, exportPublicKeyCoseAsync, generateCredentialId, generatePasskeyPairAsync, generateVaultKey, hexToBytes, importPrivateKeyAsync, importPublicKeyAsync, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, signWithPasskeyAsync, sortObjectKeysRecursively, unwrapKey, verifyExtensionSignature, verifyWithPasskeyAsync, wrapKey };
package/dist/index.d.ts CHANGED
@@ -532,6 +532,78 @@ declare function decryptCrdtData<T = object>(encryptedData: string, nonce: strin
532
532
  declare function arrayBufferToBase64(buffer: ArrayBuffer | Uint8Array): string;
533
533
  declare function base64ToArrayBuffer(base64: string): Uint8Array;
534
534
 
535
+ /**
536
+ * Crypto utilities for WebAuthn/Passkey operations
537
+ * Implements ECDSA P-256 (ES256) key generation and signing
538
+ *
539
+ * Used for:
540
+ * - Generating passkey key pairs during WebAuthn registration
541
+ * - Signing authentication challenges during WebAuthn authentication
542
+ * - Exporting/importing keys for storage
543
+ *
544
+ * Browser-compatible using the Web Crypto API
545
+ */
546
+
547
+ declare const COSE_ALGORITHM: {
548
+ readonly ES256: -7;
549
+ readonly ES384: -35;
550
+ readonly ES512: -36;
551
+ readonly EdDSA: -8;
552
+ readonly RS256: -257;
553
+ };
554
+ type CoseAlgorithm = (typeof COSE_ALGORITHM)[keyof typeof COSE_ALGORITHM];
555
+ interface PasskeyKeyPair {
556
+ publicKey: CryptoKey;
557
+ privateKey: CryptoKey;
558
+ }
559
+ interface ExportedPasskeyKeyPair {
560
+ publicKeyBase64: string;
561
+ privateKeyBase64: string;
562
+ publicKeyCoseBase64: string;
563
+ }
564
+ /**
565
+ * Generates a new ECDSA P-256 key pair for passkey operations
566
+ */
567
+ declare function generatePasskeyPairAsync(): Promise<PasskeyKeyPair>;
568
+ /**
569
+ * Exports the public key in SPKI format (Base64)
570
+ */
571
+ declare function exportPublicKeyAsync(publicKey: CryptoKey): Promise<string>;
572
+ /**
573
+ * Exports the private key in PKCS8 format (Base64)
574
+ */
575
+ declare function exportPrivateKeyAsync(privateKey: CryptoKey): Promise<string>;
576
+ /**
577
+ * Exports the public key in raw format and converts to COSE key format
578
+ * Required for WebAuthn attestation response
579
+ */
580
+ declare function exportPublicKeyCoseAsync(publicKey: CryptoKey): Promise<string>;
581
+ /**
582
+ * Imports a private key from PKCS8 format (Base64)
583
+ */
584
+ declare function importPrivateKeyAsync(privateKeyBase64: string): Promise<CryptoKey>;
585
+ /**
586
+ * Imports a public key from SPKI format (Base64)
587
+ */
588
+ declare function importPublicKeyAsync(publicKeyBase64: string): Promise<CryptoKey>;
589
+ /**
590
+ * Signs data with a passkey private key using ECDSA with SHA-256
591
+ * Returns the signature in DER format (as used by WebAuthn)
592
+ */
593
+ declare function signWithPasskeyAsync(privateKey: CryptoKey, data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>;
594
+ /**
595
+ * Verifies a signature with a passkey public key
596
+ */
597
+ declare function verifyWithPasskeyAsync(publicKey: CryptoKey, signature: ArrayBuffer | Uint8Array, data: ArrayBuffer | Uint8Array): Promise<boolean>;
598
+ /**
599
+ * Generates a random credential ID (16 bytes)
600
+ */
601
+ declare function generateCredentialId(): Uint8Array;
602
+ /**
603
+ * Exports a full key pair for storage
604
+ */
605
+ declare function exportKeyPairAsync(keyPair: PasskeyKeyPair): Promise<ExportedPasskeyKeyPair>;
606
+
535
607
  declare function createHaexVaultSdk(config?: HaexHubConfig): HaexVaultSdk;
536
608
 
537
- export { ExtensionManifest, HAEXSPACE_MESSAGE_TYPES, HaexHubConfig, HaexVaultSdk, type HaexspaceMessageType, TAURI_COMMANDS, type TauriCommand, type VerifyResult, type ZipFileEntry, arrayBufferToBase64, base64ToArrayBuffer, createHaexVaultSdk, decryptCrdtData, decryptString, decryptVaultKey, decryptVaultName, deriveKeyFromPassword, encryptCrdtData, encryptString, encryptVaultKey, generateVaultKey, hexToBytes, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, sortObjectKeysRecursively, unwrapKey, verifyExtensionSignature, wrapKey };
609
+ export { COSE_ALGORITHM, type CoseAlgorithm, type ExportedPasskeyKeyPair, ExtensionManifest, HAEXSPACE_MESSAGE_TYPES, HaexHubConfig, HaexVaultSdk, type HaexspaceMessageType, type PasskeyKeyPair, TAURI_COMMANDS, type TauriCommand, type VerifyResult, type ZipFileEntry, arrayBufferToBase64, base64ToArrayBuffer, createHaexVaultSdk, decryptCrdtData, decryptString, decryptVaultKey, decryptVaultName, deriveKeyFromPassword, encryptCrdtData, encryptString, encryptVaultKey, exportKeyPairAsync, exportPrivateKeyAsync, exportPublicKeyAsync, exportPublicKeyCoseAsync, generateCredentialId, generatePasskeyPairAsync, generateVaultKey, hexToBytes, importPrivateKeyAsync, importPublicKeyAsync, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, signWithPasskeyAsync, sortObjectKeysRecursively, unwrapKey, verifyExtensionSignature, verifyWithPasskeyAsync, wrapKey };
package/dist/index.js CHANGED
@@ -1436,7 +1436,7 @@ var BackendManagement = class {
1436
1436
  async add(request) {
1437
1437
  return this.client.request(
1438
1438
  REMOTE_STORAGE_COMMANDS.addBackend,
1439
- request
1439
+ { request }
1440
1440
  );
1441
1441
  }
1442
1442
  /**
@@ -1448,7 +1448,7 @@ var BackendManagement = class {
1448
1448
  async update(request) {
1449
1449
  return this.client.request(
1450
1450
  REMOTE_STORAGE_COMMANDS.updateBackend,
1451
- request
1451
+ { request }
1452
1452
  );
1453
1453
  }
1454
1454
  /**
@@ -2389,11 +2389,177 @@ async function verifyExtensionSignature(files, manifest) {
2389
2389
  }
2390
2390
  }
2391
2391
 
2392
+ // src/crypto/passkey.ts
2393
+ function toArrayBuffer(data) {
2394
+ if (data instanceof ArrayBuffer) {
2395
+ return data;
2396
+ }
2397
+ const buffer = new ArrayBuffer(data.byteLength);
2398
+ new Uint8Array(buffer).set(data);
2399
+ return buffer;
2400
+ }
2401
+ var COSE_ALGORITHM = {
2402
+ ES256: -7,
2403
+ // ECDSA with SHA-256 and P-256 curve
2404
+ ES384: -35,
2405
+ // ECDSA with SHA-384 and P-384 curve
2406
+ ES512: -36,
2407
+ // ECDSA with SHA-512 and P-521 curve
2408
+ EdDSA: -8,
2409
+ // EdDSA (Ed25519)
2410
+ RS256: -257
2411
+ // RSASSA-PKCS1-v1_5 with SHA-256
2412
+ };
2413
+ var ES256_ALGORITHM = {
2414
+ name: "ECDSA",
2415
+ namedCurve: "P-256"
2416
+ };
2417
+ var ES256_SIGN_ALGORITHM = {
2418
+ name: "ECDSA",
2419
+ hash: "SHA-256"
2420
+ };
2421
+ async function generatePasskeyPairAsync() {
2422
+ const keyPair = await crypto.subtle.generateKey(ES256_ALGORITHM, true, ["sign", "verify"]);
2423
+ return {
2424
+ publicKey: keyPair.publicKey,
2425
+ privateKey: keyPair.privateKey
2426
+ };
2427
+ }
2428
+ async function exportPublicKeyAsync(publicKey) {
2429
+ const exported = await crypto.subtle.exportKey("spki", publicKey);
2430
+ return arrayBufferToBase64(exported);
2431
+ }
2432
+ async function exportPrivateKeyAsync(privateKey) {
2433
+ const exported = await crypto.subtle.exportKey("pkcs8", privateKey);
2434
+ return arrayBufferToBase64(exported);
2435
+ }
2436
+ async function exportPublicKeyCoseAsync(publicKey) {
2437
+ const rawKey = await crypto.subtle.exportKey("raw", publicKey);
2438
+ const rawBytes = new Uint8Array(rawKey);
2439
+ if (rawBytes.length !== 65 || rawBytes[0] !== 4) {
2440
+ throw new Error("Invalid P-256 public key format");
2441
+ }
2442
+ const x = rawBytes.slice(1, 33);
2443
+ const y = rawBytes.slice(33, 65);
2444
+ const coseKey = encodeCoseKey(x, y);
2445
+ return arrayBufferToBase64(coseKey);
2446
+ }
2447
+ async function importPrivateKeyAsync(privateKeyBase64) {
2448
+ const keyData = base64ToArrayBuffer(privateKeyBase64);
2449
+ return crypto.subtle.importKey("pkcs8", toArrayBuffer(keyData), ES256_ALGORITHM, true, ["sign"]);
2450
+ }
2451
+ async function importPublicKeyAsync(publicKeyBase64) {
2452
+ const keyData = base64ToArrayBuffer(publicKeyBase64);
2453
+ return crypto.subtle.importKey("spki", toArrayBuffer(keyData), ES256_ALGORITHM, true, ["verify"]);
2454
+ }
2455
+ async function signWithPasskeyAsync(privateKey, data) {
2456
+ const dataBuffer = data instanceof Uint8Array ? toArrayBuffer(data) : data;
2457
+ const signature = await crypto.subtle.sign(ES256_SIGN_ALGORITHM, privateKey, dataBuffer);
2458
+ return convertP1363ToDer(new Uint8Array(signature));
2459
+ }
2460
+ async function verifyWithPasskeyAsync(publicKey, signature, data) {
2461
+ const p1363Signature = convertDerToP1363(new Uint8Array(signature));
2462
+ const dataBuffer = data instanceof Uint8Array ? toArrayBuffer(data) : data;
2463
+ return crypto.subtle.verify(ES256_SIGN_ALGORITHM, publicKey, p1363Signature, dataBuffer);
2464
+ }
2465
+ function generateCredentialId() {
2466
+ return crypto.getRandomValues(new Uint8Array(16));
2467
+ }
2468
+ async function exportKeyPairAsync(keyPair) {
2469
+ const [publicKeyBase64, privateKeyBase64, publicKeyCoseBase64] = await Promise.all([
2470
+ exportPublicKeyAsync(keyPair.publicKey),
2471
+ exportPrivateKeyAsync(keyPair.privateKey),
2472
+ exportPublicKeyCoseAsync(keyPair.publicKey)
2473
+ ]);
2474
+ return {
2475
+ publicKeyBase64,
2476
+ privateKeyBase64,
2477
+ publicKeyCoseBase64
2478
+ };
2479
+ }
2480
+ function encodeCoseKey(x, y) {
2481
+ const parts = [];
2482
+ parts.push(165);
2483
+ parts.push(1, 2);
2484
+ parts.push(3, 38);
2485
+ parts.push(32, 1);
2486
+ parts.push(33);
2487
+ parts.push(88, 32);
2488
+ for (let i = 0; i < x.length; i++) {
2489
+ parts.push(x[i]);
2490
+ }
2491
+ parts.push(34);
2492
+ parts.push(88, 32);
2493
+ for (let i = 0; i < y.length; i++) {
2494
+ parts.push(y[i]);
2495
+ }
2496
+ return new Uint8Array(parts);
2497
+ }
2498
+ function convertP1363ToDer(signature) {
2499
+ const r = signature.slice(0, 32);
2500
+ const s = signature.slice(32, 64);
2501
+ const rDer = encodeIntegerDer(r);
2502
+ const sDer = encodeIntegerDer(s);
2503
+ const sequenceLength = rDer.length + sDer.length;
2504
+ const result = new Uint8Array(2 + sequenceLength);
2505
+ result[0] = 48;
2506
+ result[1] = sequenceLength;
2507
+ result.set(rDer, 2);
2508
+ result.set(sDer, 2 + rDer.length);
2509
+ return result.buffer;
2510
+ }
2511
+ function convertDerToP1363(derSignature) {
2512
+ if (derSignature[0] !== 48) {
2513
+ throw new Error("Invalid DER signature: expected SEQUENCE");
2514
+ }
2515
+ let offset = 2;
2516
+ if (derSignature[offset] !== 2) {
2517
+ throw new Error("Invalid DER signature: expected INTEGER for r");
2518
+ }
2519
+ offset++;
2520
+ const rLength = derSignature[offset];
2521
+ offset++;
2522
+ let r = derSignature.slice(offset, offset + rLength);
2523
+ offset += rLength;
2524
+ if (derSignature[offset] !== 2) {
2525
+ throw new Error("Invalid DER signature: expected INTEGER for s");
2526
+ }
2527
+ offset++;
2528
+ const sLength = derSignature[offset];
2529
+ offset++;
2530
+ let s = derSignature.slice(offset, offset + sLength);
2531
+ if (r.length === 33 && r[0] === 0) r = r.slice(1);
2532
+ if (s.length === 33 && s[0] === 0) s = s.slice(1);
2533
+ const result = new Uint8Array(64);
2534
+ result.set(r, 32 - r.length);
2535
+ result.set(s, 64 - s.length);
2536
+ return result.buffer;
2537
+ }
2538
+ function encodeIntegerDer(value) {
2539
+ let start = 0;
2540
+ while (start < value.length - 1 && value[start] === 0) {
2541
+ start++;
2542
+ }
2543
+ const trimmed = value.slice(start);
2544
+ const needsPadding = (trimmed[0] & 128) !== 0;
2545
+ const result = new Uint8Array(2 + (needsPadding ? 1 : 0) + trimmed.length);
2546
+ result[0] = 2;
2547
+ result[1] = (needsPadding ? 1 : 0) + trimmed.length;
2548
+ if (needsPadding) {
2549
+ result[2] = 0;
2550
+ result.set(trimmed, 3);
2551
+ } else {
2552
+ result.set(trimmed, 2);
2553
+ }
2554
+ return result;
2555
+ }
2556
+
2392
2557
  // src/index.ts
2393
2558
  function createHaexVaultSdk(config = {}) {
2394
2559
  return new HaexVaultSdk(config);
2395
2560
  }
2396
2561
 
2562
+ exports.COSE_ALGORITHM = COSE_ALGORITHM;
2397
2563
  exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
2398
2564
  exports.DatabaseAPI = DatabaseAPI;
2399
2565
  exports.EXTERNAL_EVENTS = EXTERNAL_EVENTS;
@@ -2423,9 +2589,17 @@ exports.deriveKeyFromPassword = deriveKeyFromPassword;
2423
2589
  exports.encryptCrdtData = encryptCrdtData;
2424
2590
  exports.encryptString = encryptString;
2425
2591
  exports.encryptVaultKey = encryptVaultKey;
2592
+ exports.exportKeyPairAsync = exportKeyPairAsync;
2593
+ exports.exportPrivateKeyAsync = exportPrivateKeyAsync;
2594
+ exports.exportPublicKeyAsync = exportPublicKeyAsync;
2595
+ exports.exportPublicKeyCoseAsync = exportPublicKeyCoseAsync;
2596
+ exports.generateCredentialId = generateCredentialId;
2597
+ exports.generatePasskeyPairAsync = generatePasskeyPairAsync;
2426
2598
  exports.generateVaultKey = generateVaultKey;
2427
2599
  exports.getTableName = getTableName;
2428
2600
  exports.hexToBytes = hexToBytes;
2601
+ exports.importPrivateKeyAsync = importPrivateKeyAsync;
2602
+ exports.importPublicKeyAsync = importPublicKeyAsync;
2429
2603
  exports.installBaseTag = installBaseTag;
2430
2604
  exports.installCookiePolyfill = installCookiePolyfill;
2431
2605
  exports.installHistoryPolyfill = installHistoryPolyfill;
@@ -2433,9 +2607,11 @@ exports.installLocalStoragePolyfill = installLocalStoragePolyfill;
2433
2607
  exports.installPolyfills = installPolyfills;
2434
2608
  exports.installSessionStoragePolyfill = installSessionStoragePolyfill;
2435
2609
  exports.isExternalClientConnected = isExternalClientConnected;
2610
+ exports.signWithPasskeyAsync = signWithPasskeyAsync;
2436
2611
  exports.sortObjectKeysRecursively = sortObjectKeysRecursively;
2437
2612
  exports.unwrapKey = unwrapKey;
2438
2613
  exports.verifyExtensionSignature = verifyExtensionSignature;
2614
+ exports.verifyWithPasskeyAsync = verifyWithPasskeyAsync;
2439
2615
  exports.wrapKey = wrapKey;
2440
2616
  //# sourceMappingURL=index.js.map
2441
2617
  //# sourceMappingURL=index.js.map