@haex-space/vault-sdk 2.5.81 → 2.5.86

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.
@@ -1,4 +1,4 @@
1
- import { D as DatabaseQueryResult, M as Migration, b as MigrationResult, W as WebRequestOptions, c as WebResponse, H as HaexHubConfig, a as ExtensionInfo, A as ApplicationContext, d as DatabasePermissionRequest, P as PermissionResponse, S as SearchResult, e as ExternalRequestHandler, f as ExternalResponse, g as EventCallback } from './types-CS-ggsXY.js';
1
+ import { D as DatabaseQueryResult, M as Migration, b as MigrationResult, W as WebRequestOptions, c as WebResponse, H as HaexHubConfig, a as ExtensionInfo, A as ApplicationContext, d as DatabasePermissionRequest, P as PermissionResponse, S as SearchResult, e as ExternalRequestHandler, f as ExternalResponse, g as EventCallback } from './types-D4ft4_oG.js';
2
2
  import { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
3
3
 
4
4
  declare class StorageAPI {
@@ -1,4 +1,4 @@
1
- import { D as DatabaseQueryResult, M as Migration, b as MigrationResult, W as WebRequestOptions, c as WebResponse, H as HaexHubConfig, a as ExtensionInfo, A as ApplicationContext, d as DatabasePermissionRequest, P as PermissionResponse, S as SearchResult, e as ExternalRequestHandler, f as ExternalResponse, g as EventCallback } from './types-CS-ggsXY.mjs';
1
+ import { D as DatabaseQueryResult, M as Migration, b as MigrationResult, W as WebRequestOptions, c as WebResponse, H as HaexHubConfig, a as ExtensionInfo, A as ApplicationContext, d as DatabasePermissionRequest, P as PermissionResponse, S as SearchResult, e as ExternalRequestHandler, f as ExternalResponse, g as EventCallback } from './types-D4ft4_oG.mjs';
2
2
  import { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
3
3
 
4
4
  declare class StorageAPI {
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { H as HaexVaultSdk } from './client-C0fkm4FE.mjs';
2
- export { D as DatabaseAPI, b as DirEntry, a as FileStat, F as FilesystemAPI, P as PermissionsAPI, A as RemoteAddBackendRequest, f as RemoteS3Config, g as RemoteS3PublicConfig, R as RemoteStorageAPI, e as RemoteStorageBackendInfo, h as RemoteStorageObjectInfo, U as RemoteUpdateBackendRequest, d as SelectFileOptions, c as SelectFolderOptions, W as WebAPI } from './client-C0fkm4FE.mjs';
3
- import { E as ExtensionManifest, H as HaexHubConfig } from './types-CS-ggsXY.mjs';
4
- export { A as ApplicationContext, t as AuthorizedClient, B as BlockedClient, C as ContextChangedEvent, F as DEFAULT_TIMEOUT, o as DatabaseColumnInfo, m as DatabaseExecuteParams, k as DatabasePermission, d as DatabasePermissionRequest, l as DatabaseQueryParams, D as DatabaseQueryResult, n as DatabaseTableInfo, X as EXTERNAL_EVENTS, z as ErrorCode, g as EventCallback, a as ExtensionInfo, v as ExternalAuthDecision, x as ExternalConnection, J as ExternalConnectionErrorCode, I as ExternalConnectionState, Y as ExternalEvent, s as ExternalRequest, r as ExternalRequestEvent, e as ExternalRequestHandler, f as ExternalResponse, O as FileChangeEvent, Q as FileChangeType, U as HAEXTENSION_EVENTS, j as HaexHubEvent, h as HaexHubRequest, i as HaexHubResponse, N as HaexVaultSdkError, V as HaextensionEvent, u as PendingAuthorization, P as PermissionResponse, y as PermissionStatus, R as RequestedExtension, p as SearchQuery, q as SearchRequestEvent, S as SearchResult, w as SessionAuthorization, T as TABLE_SEPARATOR, W as WebRequestOptions, c as WebResponse, L as canExternalClientSendRequests, G as getTableName, K as isExternalClientConnected } from './types-CS-ggsXY.mjs';
1
+ import { H as HaexVaultSdk } from './client-Y1a7Vkgk.mjs';
2
+ export { D as DatabaseAPI, b as DirEntry, a as FileStat, F as FilesystemAPI, P as PermissionsAPI, A as RemoteAddBackendRequest, f as RemoteS3Config, g as RemoteS3PublicConfig, R as RemoteStorageAPI, e as RemoteStorageBackendInfo, h as RemoteStorageObjectInfo, U as RemoteUpdateBackendRequest, d as SelectFileOptions, c as SelectFolderOptions, W as WebAPI } from './client-Y1a7Vkgk.mjs';
3
+ import { E as ExtensionManifest, H as HaexHubConfig } from './types-D4ft4_oG.mjs';
4
+ export { A as ApplicationContext, t as AuthorizedClient, B as BlockedClient, C as ContextChangedEvent, F as DEFAULT_TIMEOUT, o as DatabaseColumnInfo, m as DatabaseExecuteParams, k as DatabasePermission, d as DatabasePermissionRequest, l as DatabaseQueryParams, D as DatabaseQueryResult, n as DatabaseTableInfo, Y as EXTERNAL_EVENTS, z as ErrorCode, g as EventCallback, a as ExtensionInfo, v as ExternalAuthDecision, x as ExternalConnection, J as ExternalConnectionErrorCode, I as ExternalConnectionState, Z as ExternalEvent, s as ExternalRequest, r as ExternalRequestEvent, e as ExternalRequestHandler, f as ExternalResponse, O as FileChangeEvent, Q as FileChangeType, V as HAEXTENSION_EVENTS, j as HaexHubEvent, h as HaexHubRequest, i as HaexHubResponse, N as HaexVaultSdkError, X as HaextensionEvent, u as PendingAuthorization, P as PermissionResponse, y as PermissionStatus, R as RequestedExtension, p as SearchQuery, q as SearchRequestEvent, S as SearchResult, w as SessionAuthorization, U as SyncTablesUpdatedEvent, T as TABLE_SEPARATOR, W as WebRequestOptions, c as WebResponse, L as canExternalClientSendRequests, G as getTableName, K as isExternalClientConnected } from './types-D4ft4_oG.mjs';
5
5
  export { H as HaextensionConfig } from './config-D_HXjsEV.mjs';
6
6
  import 'drizzle-orm/sqlite-proxy';
7
7
 
@@ -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
@@ -1,7 +1,7 @@
1
- import { H as HaexVaultSdk } from './client-C8JtjQzm.js';
2
- export { D as DatabaseAPI, b as DirEntry, a as FileStat, F as FilesystemAPI, P as PermissionsAPI, A as RemoteAddBackendRequest, f as RemoteS3Config, g as RemoteS3PublicConfig, R as RemoteStorageAPI, e as RemoteStorageBackendInfo, h as RemoteStorageObjectInfo, U as RemoteUpdateBackendRequest, d as SelectFileOptions, c as SelectFolderOptions, W as WebAPI } from './client-C8JtjQzm.js';
3
- import { E as ExtensionManifest, H as HaexHubConfig } from './types-CS-ggsXY.js';
4
- export { A as ApplicationContext, t as AuthorizedClient, B as BlockedClient, C as ContextChangedEvent, F as DEFAULT_TIMEOUT, o as DatabaseColumnInfo, m as DatabaseExecuteParams, k as DatabasePermission, d as DatabasePermissionRequest, l as DatabaseQueryParams, D as DatabaseQueryResult, n as DatabaseTableInfo, X as EXTERNAL_EVENTS, z as ErrorCode, g as EventCallback, a as ExtensionInfo, v as ExternalAuthDecision, x as ExternalConnection, J as ExternalConnectionErrorCode, I as ExternalConnectionState, Y as ExternalEvent, s as ExternalRequest, r as ExternalRequestEvent, e as ExternalRequestHandler, f as ExternalResponse, O as FileChangeEvent, Q as FileChangeType, U as HAEXTENSION_EVENTS, j as HaexHubEvent, h as HaexHubRequest, i as HaexHubResponse, N as HaexVaultSdkError, V as HaextensionEvent, u as PendingAuthorization, P as PermissionResponse, y as PermissionStatus, R as RequestedExtension, p as SearchQuery, q as SearchRequestEvent, S as SearchResult, w as SessionAuthorization, T as TABLE_SEPARATOR, W as WebRequestOptions, c as WebResponse, L as canExternalClientSendRequests, G as getTableName, K as isExternalClientConnected } from './types-CS-ggsXY.js';
1
+ import { H as HaexVaultSdk } from './client-DGSamcol.js';
2
+ export { D as DatabaseAPI, b as DirEntry, a as FileStat, F as FilesystemAPI, P as PermissionsAPI, A as RemoteAddBackendRequest, f as RemoteS3Config, g as RemoteS3PublicConfig, R as RemoteStorageAPI, e as RemoteStorageBackendInfo, h as RemoteStorageObjectInfo, U as RemoteUpdateBackendRequest, d as SelectFileOptions, c as SelectFolderOptions, W as WebAPI } from './client-DGSamcol.js';
3
+ import { E as ExtensionManifest, H as HaexHubConfig } from './types-D4ft4_oG.js';
4
+ export { A as ApplicationContext, t as AuthorizedClient, B as BlockedClient, C as ContextChangedEvent, F as DEFAULT_TIMEOUT, o as DatabaseColumnInfo, m as DatabaseExecuteParams, k as DatabasePermission, d as DatabasePermissionRequest, l as DatabaseQueryParams, D as DatabaseQueryResult, n as DatabaseTableInfo, Y as EXTERNAL_EVENTS, z as ErrorCode, g as EventCallback, a as ExtensionInfo, v as ExternalAuthDecision, x as ExternalConnection, J as ExternalConnectionErrorCode, I as ExternalConnectionState, Z as ExternalEvent, s as ExternalRequest, r as ExternalRequestEvent, e as ExternalRequestHandler, f as ExternalResponse, O as FileChangeEvent, Q as FileChangeType, V as HAEXTENSION_EVENTS, j as HaexHubEvent, h as HaexHubRequest, i as HaexHubResponse, N as HaexVaultSdkError, X as HaextensionEvent, u as PendingAuthorization, P as PermissionResponse, y as PermissionStatus, R as RequestedExtension, p as SearchQuery, q as SearchRequestEvent, S as SearchResult, w as SessionAuthorization, U as SyncTablesUpdatedEvent, T as TABLE_SEPARATOR, W as WebRequestOptions, c as WebResponse, L as canExternalClientSendRequests, G as getTableName, K as isExternalClientConnected } from './types-D4ft4_oG.js';
5
5
  export { H as HaextensionConfig } from './config-D_HXjsEV.js';
6
6
  import 'drizzle-orm/sqlite-proxy';
7
7
 
@@ -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
@@ -377,7 +377,9 @@ var HAEXTENSION_EVENTS = {
377
377
  /** Search request from HaexHub */
378
378
  SEARCH_REQUEST: "haextension:search:request",
379
379
  /** File system change detected (from native file watcher) */
380
- FILE_CHANGED: "filesync:file-changed"
380
+ FILE_CHANGED: "filesync:file-changed",
381
+ /** Tables have been updated via sync (CRDT pull from server) */
382
+ SYNC_TABLES_UPDATED: "haextension:sync:tables-updated"
381
383
  };
382
384
  var EXTERNAL_EVENTS = {
383
385
  /** External request from authorized client */
@@ -2389,11 +2391,177 @@ async function verifyExtensionSignature(files, manifest) {
2389
2391
  }
2390
2392
  }
2391
2393
 
2394
+ // src/crypto/passkey.ts
2395
+ function toArrayBuffer(data) {
2396
+ if (data instanceof ArrayBuffer) {
2397
+ return data;
2398
+ }
2399
+ const buffer = new ArrayBuffer(data.byteLength);
2400
+ new Uint8Array(buffer).set(data);
2401
+ return buffer;
2402
+ }
2403
+ var COSE_ALGORITHM = {
2404
+ ES256: -7,
2405
+ // ECDSA with SHA-256 and P-256 curve
2406
+ ES384: -35,
2407
+ // ECDSA with SHA-384 and P-384 curve
2408
+ ES512: -36,
2409
+ // ECDSA with SHA-512 and P-521 curve
2410
+ EdDSA: -8,
2411
+ // EdDSA (Ed25519)
2412
+ RS256: -257
2413
+ // RSASSA-PKCS1-v1_5 with SHA-256
2414
+ };
2415
+ var ES256_ALGORITHM = {
2416
+ name: "ECDSA",
2417
+ namedCurve: "P-256"
2418
+ };
2419
+ var ES256_SIGN_ALGORITHM = {
2420
+ name: "ECDSA",
2421
+ hash: "SHA-256"
2422
+ };
2423
+ async function generatePasskeyPairAsync() {
2424
+ const keyPair = await crypto.subtle.generateKey(ES256_ALGORITHM, true, ["sign", "verify"]);
2425
+ return {
2426
+ publicKey: keyPair.publicKey,
2427
+ privateKey: keyPair.privateKey
2428
+ };
2429
+ }
2430
+ async function exportPublicKeyAsync(publicKey) {
2431
+ const exported = await crypto.subtle.exportKey("spki", publicKey);
2432
+ return arrayBufferToBase64(exported);
2433
+ }
2434
+ async function exportPrivateKeyAsync(privateKey) {
2435
+ const exported = await crypto.subtle.exportKey("pkcs8", privateKey);
2436
+ return arrayBufferToBase64(exported);
2437
+ }
2438
+ async function exportPublicKeyCoseAsync(publicKey) {
2439
+ const rawKey = await crypto.subtle.exportKey("raw", publicKey);
2440
+ const rawBytes = new Uint8Array(rawKey);
2441
+ if (rawBytes.length !== 65 || rawBytes[0] !== 4) {
2442
+ throw new Error("Invalid P-256 public key format");
2443
+ }
2444
+ const x = rawBytes.slice(1, 33);
2445
+ const y = rawBytes.slice(33, 65);
2446
+ const coseKey = encodeCoseKey(x, y);
2447
+ return arrayBufferToBase64(coseKey);
2448
+ }
2449
+ async function importPrivateKeyAsync(privateKeyBase64) {
2450
+ const keyData = base64ToArrayBuffer(privateKeyBase64);
2451
+ return crypto.subtle.importKey("pkcs8", toArrayBuffer(keyData), ES256_ALGORITHM, true, ["sign"]);
2452
+ }
2453
+ async function importPublicKeyAsync(publicKeyBase64) {
2454
+ const keyData = base64ToArrayBuffer(publicKeyBase64);
2455
+ return crypto.subtle.importKey("spki", toArrayBuffer(keyData), ES256_ALGORITHM, true, ["verify"]);
2456
+ }
2457
+ async function signWithPasskeyAsync(privateKey, data) {
2458
+ const dataBuffer = data instanceof Uint8Array ? toArrayBuffer(data) : data;
2459
+ const signature = await crypto.subtle.sign(ES256_SIGN_ALGORITHM, privateKey, dataBuffer);
2460
+ return convertP1363ToDer(new Uint8Array(signature));
2461
+ }
2462
+ async function verifyWithPasskeyAsync(publicKey, signature, data) {
2463
+ const p1363Signature = convertDerToP1363(new Uint8Array(signature));
2464
+ const dataBuffer = data instanceof Uint8Array ? toArrayBuffer(data) : data;
2465
+ return crypto.subtle.verify(ES256_SIGN_ALGORITHM, publicKey, p1363Signature, dataBuffer);
2466
+ }
2467
+ function generateCredentialId() {
2468
+ return crypto.getRandomValues(new Uint8Array(16));
2469
+ }
2470
+ async function exportKeyPairAsync(keyPair) {
2471
+ const [publicKeyBase64, privateKeyBase64, publicKeyCoseBase64] = await Promise.all([
2472
+ exportPublicKeyAsync(keyPair.publicKey),
2473
+ exportPrivateKeyAsync(keyPair.privateKey),
2474
+ exportPublicKeyCoseAsync(keyPair.publicKey)
2475
+ ]);
2476
+ return {
2477
+ publicKeyBase64,
2478
+ privateKeyBase64,
2479
+ publicKeyCoseBase64
2480
+ };
2481
+ }
2482
+ function encodeCoseKey(x, y) {
2483
+ const parts = [];
2484
+ parts.push(165);
2485
+ parts.push(1, 2);
2486
+ parts.push(3, 38);
2487
+ parts.push(32, 1);
2488
+ parts.push(33);
2489
+ parts.push(88, 32);
2490
+ for (let i = 0; i < x.length; i++) {
2491
+ parts.push(x[i]);
2492
+ }
2493
+ parts.push(34);
2494
+ parts.push(88, 32);
2495
+ for (let i = 0; i < y.length; i++) {
2496
+ parts.push(y[i]);
2497
+ }
2498
+ return new Uint8Array(parts);
2499
+ }
2500
+ function convertP1363ToDer(signature) {
2501
+ const r = signature.slice(0, 32);
2502
+ const s = signature.slice(32, 64);
2503
+ const rDer = encodeIntegerDer(r);
2504
+ const sDer = encodeIntegerDer(s);
2505
+ const sequenceLength = rDer.length + sDer.length;
2506
+ const result = new Uint8Array(2 + sequenceLength);
2507
+ result[0] = 48;
2508
+ result[1] = sequenceLength;
2509
+ result.set(rDer, 2);
2510
+ result.set(sDer, 2 + rDer.length);
2511
+ return result.buffer;
2512
+ }
2513
+ function convertDerToP1363(derSignature) {
2514
+ if (derSignature[0] !== 48) {
2515
+ throw new Error("Invalid DER signature: expected SEQUENCE");
2516
+ }
2517
+ let offset = 2;
2518
+ if (derSignature[offset] !== 2) {
2519
+ throw new Error("Invalid DER signature: expected INTEGER for r");
2520
+ }
2521
+ offset++;
2522
+ const rLength = derSignature[offset];
2523
+ offset++;
2524
+ let r = derSignature.slice(offset, offset + rLength);
2525
+ offset += rLength;
2526
+ if (derSignature[offset] !== 2) {
2527
+ throw new Error("Invalid DER signature: expected INTEGER for s");
2528
+ }
2529
+ offset++;
2530
+ const sLength = derSignature[offset];
2531
+ offset++;
2532
+ let s = derSignature.slice(offset, offset + sLength);
2533
+ if (r.length === 33 && r[0] === 0) r = r.slice(1);
2534
+ if (s.length === 33 && s[0] === 0) s = s.slice(1);
2535
+ const result = new Uint8Array(64);
2536
+ result.set(r, 32 - r.length);
2537
+ result.set(s, 64 - s.length);
2538
+ return result.buffer;
2539
+ }
2540
+ function encodeIntegerDer(value) {
2541
+ let start = 0;
2542
+ while (start < value.length - 1 && value[start] === 0) {
2543
+ start++;
2544
+ }
2545
+ const trimmed = value.slice(start);
2546
+ const needsPadding = (trimmed[0] & 128) !== 0;
2547
+ const result = new Uint8Array(2 + (needsPadding ? 1 : 0) + trimmed.length);
2548
+ result[0] = 2;
2549
+ result[1] = (needsPadding ? 1 : 0) + trimmed.length;
2550
+ if (needsPadding) {
2551
+ result[2] = 0;
2552
+ result.set(trimmed, 3);
2553
+ } else {
2554
+ result.set(trimmed, 2);
2555
+ }
2556
+ return result;
2557
+ }
2558
+
2392
2559
  // src/index.ts
2393
2560
  function createHaexVaultSdk(config = {}) {
2394
2561
  return new HaexVaultSdk(config);
2395
2562
  }
2396
2563
 
2564
+ exports.COSE_ALGORITHM = COSE_ALGORITHM;
2397
2565
  exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
2398
2566
  exports.DatabaseAPI = DatabaseAPI;
2399
2567
  exports.EXTERNAL_EVENTS = EXTERNAL_EVENTS;
@@ -2423,9 +2591,17 @@ exports.deriveKeyFromPassword = deriveKeyFromPassword;
2423
2591
  exports.encryptCrdtData = encryptCrdtData;
2424
2592
  exports.encryptString = encryptString;
2425
2593
  exports.encryptVaultKey = encryptVaultKey;
2594
+ exports.exportKeyPairAsync = exportKeyPairAsync;
2595
+ exports.exportPrivateKeyAsync = exportPrivateKeyAsync;
2596
+ exports.exportPublicKeyAsync = exportPublicKeyAsync;
2597
+ exports.exportPublicKeyCoseAsync = exportPublicKeyCoseAsync;
2598
+ exports.generateCredentialId = generateCredentialId;
2599
+ exports.generatePasskeyPairAsync = generatePasskeyPairAsync;
2426
2600
  exports.generateVaultKey = generateVaultKey;
2427
2601
  exports.getTableName = getTableName;
2428
2602
  exports.hexToBytes = hexToBytes;
2603
+ exports.importPrivateKeyAsync = importPrivateKeyAsync;
2604
+ exports.importPublicKeyAsync = importPublicKeyAsync;
2429
2605
  exports.installBaseTag = installBaseTag;
2430
2606
  exports.installCookiePolyfill = installCookiePolyfill;
2431
2607
  exports.installHistoryPolyfill = installHistoryPolyfill;
@@ -2433,9 +2609,11 @@ exports.installLocalStoragePolyfill = installLocalStoragePolyfill;
2433
2609
  exports.installPolyfills = installPolyfills;
2434
2610
  exports.installSessionStoragePolyfill = installSessionStoragePolyfill;
2435
2611
  exports.isExternalClientConnected = isExternalClientConnected;
2612
+ exports.signWithPasskeyAsync = signWithPasskeyAsync;
2436
2613
  exports.sortObjectKeysRecursively = sortObjectKeysRecursively;
2437
2614
  exports.unwrapKey = unwrapKey;
2438
2615
  exports.verifyExtensionSignature = verifyExtensionSignature;
2616
+ exports.verifyWithPasskeyAsync = verifyWithPasskeyAsync;
2439
2617
  exports.wrapKey = wrapKey;
2440
2618
  //# sourceMappingURL=index.js.map
2441
2619
  //# sourceMappingURL=index.js.map