@haex-space/vault-sdk 2.5.81 → 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.mjs CHANGED
@@ -2387,11 +2387,176 @@ async function verifyExtensionSignature(files, manifest) {
2387
2387
  }
2388
2388
  }
2389
2389
 
2390
+ // src/crypto/passkey.ts
2391
+ function toArrayBuffer(data) {
2392
+ if (data instanceof ArrayBuffer) {
2393
+ return data;
2394
+ }
2395
+ const buffer = new ArrayBuffer(data.byteLength);
2396
+ new Uint8Array(buffer).set(data);
2397
+ return buffer;
2398
+ }
2399
+ var COSE_ALGORITHM = {
2400
+ ES256: -7,
2401
+ // ECDSA with SHA-256 and P-256 curve
2402
+ ES384: -35,
2403
+ // ECDSA with SHA-384 and P-384 curve
2404
+ ES512: -36,
2405
+ // ECDSA with SHA-512 and P-521 curve
2406
+ EdDSA: -8,
2407
+ // EdDSA (Ed25519)
2408
+ RS256: -257
2409
+ // RSASSA-PKCS1-v1_5 with SHA-256
2410
+ };
2411
+ var ES256_ALGORITHM = {
2412
+ name: "ECDSA",
2413
+ namedCurve: "P-256"
2414
+ };
2415
+ var ES256_SIGN_ALGORITHM = {
2416
+ name: "ECDSA",
2417
+ hash: "SHA-256"
2418
+ };
2419
+ async function generatePasskeyPairAsync() {
2420
+ const keyPair = await crypto.subtle.generateKey(ES256_ALGORITHM, true, ["sign", "verify"]);
2421
+ return {
2422
+ publicKey: keyPair.publicKey,
2423
+ privateKey: keyPair.privateKey
2424
+ };
2425
+ }
2426
+ async function exportPublicKeyAsync(publicKey) {
2427
+ const exported = await crypto.subtle.exportKey("spki", publicKey);
2428
+ return arrayBufferToBase64(exported);
2429
+ }
2430
+ async function exportPrivateKeyAsync(privateKey) {
2431
+ const exported = await crypto.subtle.exportKey("pkcs8", privateKey);
2432
+ return arrayBufferToBase64(exported);
2433
+ }
2434
+ async function exportPublicKeyCoseAsync(publicKey) {
2435
+ const rawKey = await crypto.subtle.exportKey("raw", publicKey);
2436
+ const rawBytes = new Uint8Array(rawKey);
2437
+ if (rawBytes.length !== 65 || rawBytes[0] !== 4) {
2438
+ throw new Error("Invalid P-256 public key format");
2439
+ }
2440
+ const x = rawBytes.slice(1, 33);
2441
+ const y = rawBytes.slice(33, 65);
2442
+ const coseKey = encodeCoseKey(x, y);
2443
+ return arrayBufferToBase64(coseKey);
2444
+ }
2445
+ async function importPrivateKeyAsync(privateKeyBase64) {
2446
+ const keyData = base64ToArrayBuffer(privateKeyBase64);
2447
+ return crypto.subtle.importKey("pkcs8", toArrayBuffer(keyData), ES256_ALGORITHM, true, ["sign"]);
2448
+ }
2449
+ async function importPublicKeyAsync(publicKeyBase64) {
2450
+ const keyData = base64ToArrayBuffer(publicKeyBase64);
2451
+ return crypto.subtle.importKey("spki", toArrayBuffer(keyData), ES256_ALGORITHM, true, ["verify"]);
2452
+ }
2453
+ async function signWithPasskeyAsync(privateKey, data) {
2454
+ const dataBuffer = data instanceof Uint8Array ? toArrayBuffer(data) : data;
2455
+ const signature = await crypto.subtle.sign(ES256_SIGN_ALGORITHM, privateKey, dataBuffer);
2456
+ return convertP1363ToDer(new Uint8Array(signature));
2457
+ }
2458
+ async function verifyWithPasskeyAsync(publicKey, signature, data) {
2459
+ const p1363Signature = convertDerToP1363(new Uint8Array(signature));
2460
+ const dataBuffer = data instanceof Uint8Array ? toArrayBuffer(data) : data;
2461
+ return crypto.subtle.verify(ES256_SIGN_ALGORITHM, publicKey, p1363Signature, dataBuffer);
2462
+ }
2463
+ function generateCredentialId() {
2464
+ return crypto.getRandomValues(new Uint8Array(16));
2465
+ }
2466
+ async function exportKeyPairAsync(keyPair) {
2467
+ const [publicKeyBase64, privateKeyBase64, publicKeyCoseBase64] = await Promise.all([
2468
+ exportPublicKeyAsync(keyPair.publicKey),
2469
+ exportPrivateKeyAsync(keyPair.privateKey),
2470
+ exportPublicKeyCoseAsync(keyPair.publicKey)
2471
+ ]);
2472
+ return {
2473
+ publicKeyBase64,
2474
+ privateKeyBase64,
2475
+ publicKeyCoseBase64
2476
+ };
2477
+ }
2478
+ function encodeCoseKey(x, y) {
2479
+ const parts = [];
2480
+ parts.push(165);
2481
+ parts.push(1, 2);
2482
+ parts.push(3, 38);
2483
+ parts.push(32, 1);
2484
+ parts.push(33);
2485
+ parts.push(88, 32);
2486
+ for (let i = 0; i < x.length; i++) {
2487
+ parts.push(x[i]);
2488
+ }
2489
+ parts.push(34);
2490
+ parts.push(88, 32);
2491
+ for (let i = 0; i < y.length; i++) {
2492
+ parts.push(y[i]);
2493
+ }
2494
+ return new Uint8Array(parts);
2495
+ }
2496
+ function convertP1363ToDer(signature) {
2497
+ const r = signature.slice(0, 32);
2498
+ const s = signature.slice(32, 64);
2499
+ const rDer = encodeIntegerDer(r);
2500
+ const sDer = encodeIntegerDer(s);
2501
+ const sequenceLength = rDer.length + sDer.length;
2502
+ const result = new Uint8Array(2 + sequenceLength);
2503
+ result[0] = 48;
2504
+ result[1] = sequenceLength;
2505
+ result.set(rDer, 2);
2506
+ result.set(sDer, 2 + rDer.length);
2507
+ return result.buffer;
2508
+ }
2509
+ function convertDerToP1363(derSignature) {
2510
+ if (derSignature[0] !== 48) {
2511
+ throw new Error("Invalid DER signature: expected SEQUENCE");
2512
+ }
2513
+ let offset = 2;
2514
+ if (derSignature[offset] !== 2) {
2515
+ throw new Error("Invalid DER signature: expected INTEGER for r");
2516
+ }
2517
+ offset++;
2518
+ const rLength = derSignature[offset];
2519
+ offset++;
2520
+ let r = derSignature.slice(offset, offset + rLength);
2521
+ offset += rLength;
2522
+ if (derSignature[offset] !== 2) {
2523
+ throw new Error("Invalid DER signature: expected INTEGER for s");
2524
+ }
2525
+ offset++;
2526
+ const sLength = derSignature[offset];
2527
+ offset++;
2528
+ let s = derSignature.slice(offset, offset + sLength);
2529
+ if (r.length === 33 && r[0] === 0) r = r.slice(1);
2530
+ if (s.length === 33 && s[0] === 0) s = s.slice(1);
2531
+ const result = new Uint8Array(64);
2532
+ result.set(r, 32 - r.length);
2533
+ result.set(s, 64 - s.length);
2534
+ return result.buffer;
2535
+ }
2536
+ function encodeIntegerDer(value) {
2537
+ let start = 0;
2538
+ while (start < value.length - 1 && value[start] === 0) {
2539
+ start++;
2540
+ }
2541
+ const trimmed = value.slice(start);
2542
+ const needsPadding = (trimmed[0] & 128) !== 0;
2543
+ const result = new Uint8Array(2 + (needsPadding ? 1 : 0) + trimmed.length);
2544
+ result[0] = 2;
2545
+ result[1] = (needsPadding ? 1 : 0) + trimmed.length;
2546
+ if (needsPadding) {
2547
+ result[2] = 0;
2548
+ result.set(trimmed, 3);
2549
+ } else {
2550
+ result.set(trimmed, 2);
2551
+ }
2552
+ return result;
2553
+ }
2554
+
2390
2555
  // src/index.ts
2391
2556
  function createHaexVaultSdk(config = {}) {
2392
2557
  return new HaexVaultSdk(config);
2393
2558
  }
2394
2559
 
2395
- export { DEFAULT_TIMEOUT, DatabaseAPI, EXTERNAL_EVENTS, ErrorCode, ExternalConnectionErrorCode, ExternalConnectionState, FilesystemAPI, HAEXSPACE_MESSAGE_TYPES, HAEXTENSION_EVENTS, HaexVaultSdk, HaexVaultSdkError, PermissionStatus, PermissionsAPI, RemoteStorageAPI, TABLE_SEPARATOR, TAURI_COMMANDS, WebAPI, arrayBufferToBase64, base64ToArrayBuffer, canExternalClientSendRequests, createHaexVaultSdk, decryptCrdtData, decryptString, decryptVaultKey, decryptVaultName, deriveKeyFromPassword, encryptCrdtData, encryptString, encryptVaultKey, generateVaultKey, getTableName, hexToBytes, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, isExternalClientConnected, sortObjectKeysRecursively, unwrapKey, verifyExtensionSignature, wrapKey };
2560
+ export { COSE_ALGORITHM, DEFAULT_TIMEOUT, DatabaseAPI, EXTERNAL_EVENTS, ErrorCode, ExternalConnectionErrorCode, ExternalConnectionState, FilesystemAPI, HAEXSPACE_MESSAGE_TYPES, HAEXTENSION_EVENTS, HaexVaultSdk, HaexVaultSdkError, PermissionStatus, PermissionsAPI, RemoteStorageAPI, TABLE_SEPARATOR, TAURI_COMMANDS, WebAPI, arrayBufferToBase64, base64ToArrayBuffer, canExternalClientSendRequests, createHaexVaultSdk, decryptCrdtData, decryptString, decryptVaultKey, decryptVaultName, deriveKeyFromPassword, encryptCrdtData, encryptString, encryptVaultKey, exportKeyPairAsync, exportPrivateKeyAsync, exportPublicKeyAsync, exportPublicKeyCoseAsync, generateCredentialId, generatePasskeyPairAsync, generateVaultKey, getTableName, hexToBytes, importPrivateKeyAsync, importPublicKeyAsync, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, isExternalClientConnected, signWithPasskeyAsync, sortObjectKeysRecursively, unwrapKey, verifyExtensionSignature, verifyWithPasskeyAsync, wrapKey };
2396
2561
  //# sourceMappingURL=index.mjs.map
2397
2562
  //# sourceMappingURL=index.mjs.map