@haex-space/vault-sdk 4.8.1 → 4.9.0
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/README.md +53 -0
- package/dist/{client-CNbwFQjB.d.ts → client-BzgCo_Ch.d.ts} +175 -3
- package/dist/{client-DOAj36ga.d.mts → client-CS0AdXto.d.mts} +175 -3
- package/dist/index.d.mts +48 -7
- package/dist/index.d.ts +48 -7
- package/dist/index.js +192 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +188 -1
- package/dist/index.mjs.map +1 -1
- package/dist/node.d.mts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +186 -0
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +186 -0
- package/dist/react.mjs.map +1 -1
- package/dist/runtime/nuxt.plugin.client.js +183 -0
- package/dist/runtime/nuxt.plugin.client.js.map +1 -1
- package/dist/runtime/nuxt.plugin.client.mjs +183 -0
- package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
- package/dist/svelte.d.mts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.js +186 -0
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +186 -0
- package/dist/svelte.mjs.map +1 -1
- package/dist/{types-3iifP-Q1.d.mts → types-BZVkX0Wf.d.mts} +24 -2
- package/dist/{types-3iifP-Q1.d.ts → types-BZVkX0Wf.d.ts} +24 -2
- package/dist/vue.d.mts +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +186 -0
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +186 -0
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -765,6 +765,18 @@ var MODEL_JOB_EVENTS = {
|
|
|
765
765
|
/** A job of this frame ended: completed, failed or cancelled. */
|
|
766
766
|
COMPLETED: "haextension:model-job:completed"
|
|
767
767
|
};
|
|
768
|
+
var PEERS_EVENTS = {
|
|
769
|
+
/** The outcome of an invitation, once per invitation (inviting side). */
|
|
770
|
+
INVITE_STATUS: "peers:invite-status",
|
|
771
|
+
/** A channel opened after the user accepted an invitation in holzi's prompt (invited side). */
|
|
772
|
+
CHANNEL_OPENED: "peers:channel-opened",
|
|
773
|
+
/** A device joined one of this device's lobbies by code (host). */
|
|
774
|
+
JOINED: "peers:joined",
|
|
775
|
+
/** A message on a channel; `data` is Base64 on the bridge. */
|
|
776
|
+
MESSAGE: "peers:message",
|
|
777
|
+
/** A channel ended: closed, lost or timed out. */
|
|
778
|
+
CHANNEL_CLOSED: "peers:channel-closed"
|
|
779
|
+
};
|
|
768
780
|
var EXTERNAL_EVENTS = {
|
|
769
781
|
/** External request from authorized client */
|
|
770
782
|
REQUEST: "haextension:external:request",
|
|
@@ -1206,6 +1218,27 @@ var MODEL_COMMANDS = {
|
|
|
1206
1218
|
cancel: "extension_model_job_cancel"
|
|
1207
1219
|
};
|
|
1208
1220
|
|
|
1221
|
+
// src/commands/peers.ts
|
|
1222
|
+
init_esm_shims();
|
|
1223
|
+
var PEER_COMMANDS = {
|
|
1224
|
+
/** Invites a contact; the outcome follows as `peers:invite-status` */
|
|
1225
|
+
invite: "extension_peers_invite",
|
|
1226
|
+
/** Withdraws an open invitation on all devices of the contact */
|
|
1227
|
+
inviteCancel: "extension_peers_invite_cancel",
|
|
1228
|
+
/** Opens a lobby and returns its join code */
|
|
1229
|
+
lobbyOpen: "extension_peers_lobby_open",
|
|
1230
|
+
/** Closes a lobby; its code stops working, its channels stay open */
|
|
1231
|
+
lobbyClose: "extension_peers_lobby_close",
|
|
1232
|
+
/** Joins a lobby by its code; waits at most 15 s for the host */
|
|
1233
|
+
join: "extension_peers_join",
|
|
1234
|
+
/** Closes a channel of an own lobby and keeps the device out of that lobby */
|
|
1235
|
+
remove: "extension_peers_remove",
|
|
1236
|
+
/** Sends a fast or a reliable message over a channel */
|
|
1237
|
+
send: "extension_peers_send",
|
|
1238
|
+
/** Closes a channel on both sides */
|
|
1239
|
+
close: "extension_peers_close"
|
|
1240
|
+
};
|
|
1241
|
+
|
|
1209
1242
|
// src/commands/mail.ts
|
|
1210
1243
|
init_esm_shims();
|
|
1211
1244
|
var MAIL_COMMANDS = {
|
|
@@ -1265,6 +1298,7 @@ var TAURI_COMMANDS = {
|
|
|
1265
1298
|
passwords: PASSWORD_COMMANDS,
|
|
1266
1299
|
contacts: CONTACT_COMMANDS,
|
|
1267
1300
|
models: MODEL_COMMANDS,
|
|
1301
|
+
peers: PEER_COMMANDS,
|
|
1268
1302
|
mail: MAIL_COMMANDS,
|
|
1269
1303
|
notifications: NOTIFICATION_COMMANDS
|
|
1270
1304
|
};
|
|
@@ -2531,6 +2565,158 @@ var ModelsAPI = class {
|
|
|
2531
2565
|
}
|
|
2532
2566
|
};
|
|
2533
2567
|
|
|
2568
|
+
// src/api/peers.ts
|
|
2569
|
+
init_esm_shims();
|
|
2570
|
+
init_vaultKey();
|
|
2571
|
+
var PEER_ERROR_KINDS = {
|
|
2572
|
+
contact_unknown: "PEER_CONTACT_UNKNOWN",
|
|
2573
|
+
invite_not_open: "PEER_INVITE_UNKNOWN",
|
|
2574
|
+
channel_unknown: "PEER_CHANNEL_CLOSED",
|
|
2575
|
+
channel_closed: "PEER_CHANNEL_CLOSED",
|
|
2576
|
+
too_large: "PEER_PAYLOAD_TOO_LARGE",
|
|
2577
|
+
lobby_closed: "PEER_LOBBY_CLOSED",
|
|
2578
|
+
not_admitted: "PEER_NOT_ALLOWED",
|
|
2579
|
+
limit: "PEER_LIMIT",
|
|
2580
|
+
network_unavailable: "PEER_NETWORK_UNAVAILABLE",
|
|
2581
|
+
invalid_input: "PEER_INVALID_INPUT"
|
|
2582
|
+
};
|
|
2583
|
+
var PeerError = class extends Error {
|
|
2584
|
+
constructor(code, reason, message, details = {}, options) {
|
|
2585
|
+
super(message, options);
|
|
2586
|
+
this.code = code;
|
|
2587
|
+
this.reason = reason;
|
|
2588
|
+
this.details = details;
|
|
2589
|
+
this.name = "PeerError";
|
|
2590
|
+
this.kind = PEER_ERROR_KINDS[reason];
|
|
2591
|
+
if (typeof details.limit === "number") this.limit = details.limit;
|
|
2592
|
+
}
|
|
2593
|
+
};
|
|
2594
|
+
function isPeerErrorReason(value) {
|
|
2595
|
+
return typeof value === "string" && Object.hasOwn(PEER_ERROR_KINDS, value);
|
|
2596
|
+
}
|
|
2597
|
+
function toPeerError(error) {
|
|
2598
|
+
if (typeof error !== "object" || error === null) return error;
|
|
2599
|
+
const { code, message, details } = error;
|
|
2600
|
+
if (typeof code !== "number" || typeof details !== "object" || details === null) return error;
|
|
2601
|
+
const reason = details.reason;
|
|
2602
|
+
if (!isPeerErrorReason(reason)) return error;
|
|
2603
|
+
return new PeerError(
|
|
2604
|
+
code,
|
|
2605
|
+
reason,
|
|
2606
|
+
typeof message === "string" ? message : reason,
|
|
2607
|
+
details,
|
|
2608
|
+
{ cause: error }
|
|
2609
|
+
);
|
|
2610
|
+
}
|
|
2611
|
+
var EVENT_NAMES = {
|
|
2612
|
+
"invite-status": PEERS_EVENTS.INVITE_STATUS,
|
|
2613
|
+
"channel-opened": PEERS_EVENTS.CHANNEL_OPENED,
|
|
2614
|
+
joined: PEERS_EVENTS.JOINED,
|
|
2615
|
+
message: PEERS_EVENTS.MESSAGE,
|
|
2616
|
+
"channel-closed": PEERS_EVENTS.CHANNEL_CLOSED
|
|
2617
|
+
};
|
|
2618
|
+
function decodeEvent(type, data) {
|
|
2619
|
+
if (typeof data !== "object" || data === null) return void 0;
|
|
2620
|
+
if (type !== "message") return data;
|
|
2621
|
+
const message = data;
|
|
2622
|
+
if (typeof message.channelId !== "string" || typeof message.data !== "string") return void 0;
|
|
2623
|
+
let decoded;
|
|
2624
|
+
try {
|
|
2625
|
+
decoded = base64ToArrayBuffer(message.data);
|
|
2626
|
+
} catch {
|
|
2627
|
+
return void 0;
|
|
2628
|
+
}
|
|
2629
|
+
if (arrayBufferToBase64(decoded) !== message.data) return void 0;
|
|
2630
|
+
return {
|
|
2631
|
+
channelId: message.channelId,
|
|
2632
|
+
data: decoded,
|
|
2633
|
+
reliable: message.reliable === true
|
|
2634
|
+
};
|
|
2635
|
+
}
|
|
2636
|
+
var PeersAPI = class {
|
|
2637
|
+
constructor(client) {
|
|
2638
|
+
this.client = client;
|
|
2639
|
+
/** Largest fast message (`reliable: false`) in bytes. */
|
|
2640
|
+
this.MAX_FAST_BYTES = 1024;
|
|
2641
|
+
/** Largest reliable message in bytes. */
|
|
2642
|
+
this.MAX_RELIABLE_BYTES = 65536;
|
|
2643
|
+
/** Largest `payload` of an invitation or a join, as JSON, in bytes. */
|
|
2644
|
+
this.MAX_PAYLOAD_BYTES = 4096;
|
|
2645
|
+
}
|
|
2646
|
+
async call(method, params) {
|
|
2647
|
+
try {
|
|
2648
|
+
return await this.client.request(method, params);
|
|
2649
|
+
} catch (error) {
|
|
2650
|
+
throw toPeerError(error);
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
/** Invites a contact; the outcome follows as `invite-status` with this `inviteId`. */
|
|
2654
|
+
async inviteAsync(contactId, payload) {
|
|
2655
|
+
const answer = await this.call(PEER_COMMANDS.invite, { contactId, payload });
|
|
2656
|
+
return { inviteId: answer.inviteId };
|
|
2657
|
+
}
|
|
2658
|
+
/** Withdraws an open invitation on all devices of the contact; no `invite-status` follows. */
|
|
2659
|
+
async cancelInviteAsync(inviteId) {
|
|
2660
|
+
await this.call(PEER_COMMANDS.inviteCancel, { inviteId });
|
|
2661
|
+
}
|
|
2662
|
+
/**
|
|
2663
|
+
* Opens a lobby; `lobbyId` is 1–64 characters of `[A-Za-z0-9._-]`. The join code is opaque:
|
|
2664
|
+
* hand it on as it is.
|
|
2665
|
+
*/
|
|
2666
|
+
async openLobbyAsync(lobbyId, visibility) {
|
|
2667
|
+
const answer = await this.call(PEER_COMMANDS.lobbyOpen, { lobbyId, visibility });
|
|
2668
|
+
return { joinCode: answer.joinCode };
|
|
2669
|
+
}
|
|
2670
|
+
/** Closes a lobby: its code stops working, its channels stay open. An unknown lobby is fine. */
|
|
2671
|
+
async closeLobbyAsync(lobbyId) {
|
|
2672
|
+
await this.call(PEER_COMMANDS.lobbyClose, { lobbyId });
|
|
2673
|
+
}
|
|
2674
|
+
/**
|
|
2675
|
+
* Joins a lobby by its code with a self-chosen `displayName` (1–64 characters). The host
|
|
2676
|
+
* answers within 15 s; a lobby that cannot be joined for any reason rejects as `lobby_closed`.
|
|
2677
|
+
*/
|
|
2678
|
+
async joinAsync(joinCode, displayName, payload) {
|
|
2679
|
+
const answer = await this.call(PEER_COMMANDS.join, {
|
|
2680
|
+
joinCode,
|
|
2681
|
+
displayName,
|
|
2682
|
+
payload
|
|
2683
|
+
});
|
|
2684
|
+
return { channelId: answer.channelId, lobbyId: answer.lobbyId };
|
|
2685
|
+
}
|
|
2686
|
+
/** Closes a channel of an own lobby and keeps that device (and vault) out of the lobby. */
|
|
2687
|
+
async removeAsync(channelId) {
|
|
2688
|
+
await this.call(PEER_COMMANDS.remove, { channelId });
|
|
2689
|
+
}
|
|
2690
|
+
/**
|
|
2691
|
+
* Sends bytes over a channel: fast (default, at most {@link MAX_FAST_BYTES}, may be lost) or
|
|
2692
|
+
* `reliable` (at most {@link MAX_RELIABLE_BYTES}, in order; 16 may wait per channel).
|
|
2693
|
+
*/
|
|
2694
|
+
async sendAsync(channelId, data, options = {}) {
|
|
2695
|
+
await this.call(PEER_COMMANDS.send, {
|
|
2696
|
+
channelId,
|
|
2697
|
+
data: { $bytes: arrayBufferToBase64(data) },
|
|
2698
|
+
reliable: options.reliable ?? false
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2701
|
+
/** Closes a channel; both sides get `channel-closed` with `reason: "closed"`. */
|
|
2702
|
+
async closeAsync(channelId) {
|
|
2703
|
+
await this.call(PEER_COMMANDS.close, { channelId });
|
|
2704
|
+
}
|
|
2705
|
+
/**
|
|
2706
|
+
* Listens for one of the peers events (`invite-status`, `channel-opened`, `joined`, `message`,
|
|
2707
|
+
* `channel-closed`); `message.data` arrives as bytes. Returns an unsubscribe function.
|
|
2708
|
+
*/
|
|
2709
|
+
on(type, handler) {
|
|
2710
|
+
const name = EVENT_NAMES[type];
|
|
2711
|
+
const wrapped = (event) => {
|
|
2712
|
+
const decoded = decodeEvent(type, event.data);
|
|
2713
|
+
if (decoded) handler(decoded);
|
|
2714
|
+
};
|
|
2715
|
+
this.client.on(name, wrapped);
|
|
2716
|
+
return () => this.client.off(name, wrapped);
|
|
2717
|
+
}
|
|
2718
|
+
};
|
|
2719
|
+
|
|
2534
2720
|
// src/api/mail.ts
|
|
2535
2721
|
init_esm_shims();
|
|
2536
2722
|
var MailAPI = class {
|
|
@@ -3648,6 +3834,7 @@ var HaexVaultSdk = class {
|
|
|
3648
3834
|
this.passwords = new PasswordsAPI(this);
|
|
3649
3835
|
this.contacts = new ContactsAPI(this);
|
|
3650
3836
|
this.models = new ModelsAPI(this);
|
|
3837
|
+
this.peers = new PeersAPI(this);
|
|
3651
3838
|
this.mail = new MailAPI(this);
|
|
3652
3839
|
this.notifications = new NotificationsAPI(this);
|
|
3653
3840
|
this.tab = new TabAPI(this);
|
|
@@ -4517,6 +4704,6 @@ function createHaexVaultSdk(config = {}) {
|
|
|
4517
4704
|
return new HaexVaultSdk(config);
|
|
4518
4705
|
}
|
|
4519
4706
|
|
|
4520
|
-
export { CONTACT_COMMANDS, COSE_ALGORITHM, ContactsAPI, DEFAULT_TIMEOUT, DatabaseAPI, DialogAPI, ENCRYPTED_FOLDER_COMMANDS, EXTERNAL_EVENTS, EncryptedFoldersAPI, ErrorCode, ExternalConnectionErrorCode, ExternalConnectionState, FilesystemAPI, HAEXSPACE_MESSAGE_TYPES, HAEXTENSION_EVENTS, HaexVaultSdk, HaexVaultSdkError, HostErrorCode, KEY_AGREEMENT_ALGO, KnownPath, LOCALSEND_EVENTS, LocalSendAPI, MAIL_COMMANDS, MAIL_EVENTS, MODEL_COMMANDS, MODEL_JOB_EVENTS, MailAPI, ModelsAPI, NOTIFICATION_COMMANDS, NOTIFICATION_EVENTS, NotificationsAPI, PASSWORD_COMMANDS, PasswordsAPI, PermissionErrorCode, PermissionStatus, PermissionsAPI, RemoteStorageAPI, SHELL_EVENTS, SIGNING_ALGO, SPACE_COMMANDS, ShellAPI, SpacesAPI, TABLE_SEPARATOR, TAURI_COMMANDS, TabAPI, ToolsAPI, WebAPI, arrayBufferToBase64, base58btcDecode, base58btcEncode, base64ToArrayBuffer, canExternalClientSendRequests, createHaexVaultSdk, decryptCrdtData, decryptPrivateKeyAsync, decryptSpaceNameAsync, decryptString, decryptVaultKey, decryptVaultName, decryptWithPrivateKeyAsync, deriveKeyFromPassword, didKeyToPublicKeyAsync, encryptCrdtData, encryptPrivateKeyAsync, encryptSpaceNameAsync, encryptString, encryptVaultKey, encryptWithPublicKeyAsync, exportKeyPairAsync, exportPrivateKeyAsync, exportPublicKeyAsync, exportPublicKeyCoseAsync, exportUserKeypairAsync, generateCredentialId, generateIdentityAsync, generatePasskeyPairAsync, generateSpaceKey, generateUserKeypairAsync, generateVaultKey, getTableName, importPrivateKeyAsync, importPrivateKeyForKeyAgreementAsync, importPublicKeyAsync, importPublicKeyForKeyAgreementAsync, importUserPrivateKeyAsync, importUserPublicKeyAsync, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, isExternalClientConnected, isPermissionDeniedError, isPermissionError, isPermissionPromptError, publicKeyToDidKeyAsync, signClaimPresentationAsync, signRecordAsync, signSpaceChallengeAsync, signWithPasskeyAsync, unwrapKey, verifyClaimPresentationAsync, verifyRecordSignatureAsync, verifySpaceChallengeAsync, verifyWithPasskeyAsync, wrapKey };
|
|
4707
|
+
export { CONTACT_COMMANDS, COSE_ALGORITHM, ContactsAPI, DEFAULT_TIMEOUT, DatabaseAPI, DialogAPI, ENCRYPTED_FOLDER_COMMANDS, EXTERNAL_EVENTS, EncryptedFoldersAPI, ErrorCode, ExternalConnectionErrorCode, ExternalConnectionState, FilesystemAPI, HAEXSPACE_MESSAGE_TYPES, HAEXTENSION_EVENTS, HaexVaultSdk, HaexVaultSdkError, HostErrorCode, KEY_AGREEMENT_ALGO, KnownPath, LOCALSEND_EVENTS, LocalSendAPI, MAIL_COMMANDS, MAIL_EVENTS, MODEL_COMMANDS, MODEL_JOB_EVENTS, MailAPI, ModelsAPI, NOTIFICATION_COMMANDS, NOTIFICATION_EVENTS, NotificationsAPI, PASSWORD_COMMANDS, PEERS_EVENTS, PEER_COMMANDS, PEER_ERROR_KINDS, PasswordsAPI, PeerError, PeersAPI, PermissionErrorCode, PermissionStatus, PermissionsAPI, RemoteStorageAPI, SHELL_EVENTS, SIGNING_ALGO, SPACE_COMMANDS, ShellAPI, SpacesAPI, TABLE_SEPARATOR, TAURI_COMMANDS, TabAPI, ToolsAPI, WebAPI, arrayBufferToBase64, base58btcDecode, base58btcEncode, base64ToArrayBuffer, canExternalClientSendRequests, createHaexVaultSdk, decryptCrdtData, decryptPrivateKeyAsync, decryptSpaceNameAsync, decryptString, decryptVaultKey, decryptVaultName, decryptWithPrivateKeyAsync, deriveKeyFromPassword, didKeyToPublicKeyAsync, encryptCrdtData, encryptPrivateKeyAsync, encryptSpaceNameAsync, encryptString, encryptVaultKey, encryptWithPublicKeyAsync, exportKeyPairAsync, exportPrivateKeyAsync, exportPublicKeyAsync, exportPublicKeyCoseAsync, exportUserKeypairAsync, generateCredentialId, generateIdentityAsync, generatePasskeyPairAsync, generateSpaceKey, generateUserKeypairAsync, generateVaultKey, getTableName, importPrivateKeyAsync, importPrivateKeyForKeyAgreementAsync, importPublicKeyAsync, importPublicKeyForKeyAgreementAsync, importUserPrivateKeyAsync, importUserPublicKeyAsync, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, isExternalClientConnected, isPermissionDeniedError, isPermissionError, isPermissionPromptError, publicKeyToDidKeyAsync, signClaimPresentationAsync, signRecordAsync, signSpaceChallengeAsync, signWithPasskeyAsync, unwrapKey, verifyClaimPresentationAsync, verifyRecordSignatureAsync, verifySpaceChallengeAsync, verifyWithPasskeyAsync, wrapKey };
|
|
4521
4708
|
//# sourceMappingURL=index.mjs.map
|
|
4522
4709
|
//# sourceMappingURL=index.mjs.map
|