p2party 0.7.2 → 0.7.4
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 +4 -2
- package/lib/api/webrtc/disconnectFromAllRoomsQuery.d.ts.map +1 -1
- package/lib/api/webrtc/disconnectFromPeerChannelLabelQuery.d.ts.map +1 -1
- package/lib/api/webrtc/disconnectFromPeerQuery.d.ts.map +1 -1
- package/lib/api/webrtc/disconnectFromRoomQuery.d.ts.map +1 -1
- package/lib/api/webrtc/disconnectQuery.d.ts.map +1 -1
- package/lib/api/webrtc/interfaces.d.ts +1 -0
- package/lib/api/webrtc/interfaces.d.ts.map +1 -1
- package/lib/api/webrtc/setCandidateQuery.d.ts.map +1 -1
- package/lib/api/webrtc/setDescriptionQuery.d.ts.map +1 -1
- package/lib/db.worker.js +1 -1
- package/lib/handlers/handleChallenge.d.ts +2 -2
- package/lib/handlers/handleConnectToPeer.d.ts +4 -1
- package/lib/handlers/handleOpenChannel.d.ts +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -1
- package/lib/index.min.js +1 -1
- package/lib/index.mjs +1 -1
- package/package.json +5 -5
- package/lib/cryptography/hasher.d.ts +0 -11
- package/lib/utils/mediasource.d.ts +0 -2
package/README.md
CHANGED
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
|
|
18
18
|
[code-style-prettier-url]: https://github.com/prettier/prettier
|
|
19
19
|
|
|
20
|
-
> Peer-to-peer WebRTC mesh networking with
|
|
20
|
+
> Peer-to-peer WebRTC mesh networking with "offensive" cryptographic.
|
|
21
21
|
|
|
22
|
-
**p2party** connects peers visiting the same URL into a WebRTC mesh network and enables secure
|
|
22
|
+
**p2party** connects peers visiting the same URL into a WebRTC mesh network and enables secure message exchange of any size over ephemeral data channels. Unlike traditional privacy-enabling libraries, `p2party` obfuscates traffic using noisy and randomized padding of real information, isomorphic packet transmission (64kb), making message intent opaque. Of course it also adds a layer of ChaChaPoly1305 end-to-end encryption with ephemeral Ed25519 sender keys.
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
@@ -448,6 +448,8 @@ const removePeerFromBlacklist = async (peerId?: string, peerPublicKey?: string)
|
|
|
448
448
|
|
|
449
449
|
```
|
|
450
450
|
|
|
451
|
+
Because a message is split into chunks with noisy padding for which we need to calculate Merkle proofs, it may take some time for the process to finish before starting transmitting the information over a channel.
|
|
452
|
+
|
|
451
453
|
## Development
|
|
452
454
|
|
|
453
455
|
If you want to build the library yourselves, you need to have [Emscripten](https://github.com/emscripten-core/emscripten)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disconnectFromAllRoomsQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/disconnectFromAllRoomsQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"disconnectFromAllRoomsQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/disconnectFromAllRoomsQuery.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,+BAA+B,EAChC,MAAM,cAAc,CAAC;AAItB,MAAM,WAAW,wCACf,SAAQ,+BAA+B;IACvC,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,YAAY,EAAE,eAAe,EAAE,CAAC;CACjC;AAED,QAAA,MAAM,6BAA6B,EAAE,WAAW,CAC9C,wCAAwC,EACxC,IAAI,EACJ,OAAO,CAqFR,CAAC;AAEF,eAAe,6BAA6B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disconnectFromPeerChannelLabelQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/disconnectFromPeerChannelLabelQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"disconnectFromPeerChannelLabelQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/disconnectFromPeerChannelLabelQuery.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,uCAAuC,EACxC,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,gDACf,SAAQ,uCAAuC;IAC/C,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,YAAY,EAAE,eAAe,EAAE,CAAC;CACjC;AAED,QAAA,MAAM,yCAAyC,EAAE,WAAW,CAC1D,gDAAgD,EAChD,IAAI,EACJ,OAAO,CAgFR,CAAC;AAEF,eAAe,yCAAyC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disconnectFromPeerQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/disconnectFromPeerQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,oCACf,SAAQ,2BAA2B;IACnC,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,YAAY,EAAE,eAAe,EAAE,CAAC;CACjC;AAED,QAAA,MAAM,yBAAyB,EAAE,WAAW,CAC1C,oCAAoC,EACpC,IAAI,EACJ,OAAO,
|
|
1
|
+
{"version":3,"file":"disconnectFromPeerQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/disconnectFromPeerQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,oCACf,SAAQ,2BAA2B;IACnC,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,YAAY,EAAE,eAAe,EAAE,CAAC;CACjC;AAED,QAAA,MAAM,yBAAyB,EAAE,WAAW,CAC1C,oCAAoC,EACpC,IAAI,EACJ,OAAO,CAqDR,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disconnectFromRoomQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/disconnectFromRoomQuery.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,2BAA2B,EAC5B,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"disconnectFromRoomQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/disconnectFromRoomQuery.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,oCACf,SAAQ,2BAA2B;IACnC,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,YAAY,EAAE,eAAe,EAAE,CAAC;CACjC;AAED,QAAA,MAAM,yBAAyB,EAAE,WAAW,CAC1C,oCAAoC,EACpC,IAAI,EACJ,OAAO,CA6DR,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disconnectQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/disconnectQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"disconnectQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/disconnectQuery.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,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,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,2BAA2B;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,+BAA+B;IAC9C,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,2BAA2B;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,mCAAmC;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,MAAM,WAAW,uCAAuC;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setCandidateQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/setCandidateQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setCandidateQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/setCandidateQuery.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAItB,MAAM,WAAW,8BAA+B,SAAQ,qBAAqB;IAC3E,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,aAAa,EAAE,gBAAgB,EAAE,CAAC;CACnC;AAED,QAAA,MAAM,0BAA0B,EAAE,WAAW,CAC3C,8BAA8B,EAC9B,IAAI,EACJ,OAAO,CAiFR,CAAC;AAEF,eAAe,0BAA0B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setDescriptionQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/setDescriptionQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setDescriptionQuery.d.ts","sourceRoot":"","sources":["../../../src/api/webrtc/setDescriptionQuery.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAK,EACV,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EAChB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,gCACf,SAAQ,uBAAuB;IAC/B,eAAe,EAAE,kBAAkB,EAAE,CAAC;IACtC,aAAa,EAAE,gBAAgB,EAAE,CAAC;IAClC,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAAC;IACzC,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC;CACtC;AAED,QAAA,MAAM,yBAAyB,EAAE,WAAW,CAC1C,gCAAgC,EAChC,IAAI,EACJ,OAAO,CA+HR,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
|
package/lib/db.worker.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=(e,t)=>t.some(t=>e instanceof t);let t,a;const n=new WeakMap,o=new WeakMap,r=new WeakMap;let s={get(e,t,a){if(e instanceof IDBTransaction){if("done"===t)return n.get(e);if("store"===t)return a.objectStoreNames[1]?void 0:a.objectStore(a.objectStoreNames[0])}return d(e[t])},set:(e,t,a)=>(e[t]=a,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function i(e){s=e(s)}function c(e){return(a||(a=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(l(this),t),d(this.request)}:function(...t){return d(e.apply(l(this),t))}}function u(a){return"function"==typeof a?c(a):(a instanceof IDBTransaction&&function(e){if(n.has(e))return;const t=new Promise((t,a)=>{const n=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",r),e.removeEventListener("abort",r)},o=()=>{t(),n()},r=()=>{a(e.error||new DOMException("AbortError","AbortError")),n()};e.addEventListener("complete",o),e.addEventListener("error",r),e.addEventListener("abort",r)});n.set(e,t)}(a),e(a,t||(t=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(a,s):a)}function d(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,a)=>{const n=()=>{e.removeEventListener("success",o),e.removeEventListener("error",r)},o=()=>{t(d(e.result)),n()},r=()=>{a(e.error),n()};e.addEventListener("success",o),e.addEventListener("error",r)});return r.set(t,e),t}(e);if(o.has(e))return o.get(e);const t=u(e);return t!==e&&(o.set(e,t),r.set(t,e)),t}const l=e=>r.get(e);const w=["get","getKey","getAll","getAllKeys","count"],h=["put","add","delete","clear"],m=new Map;function g(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(m.get(t))return m.get(t);const a=t.replace(/FromIndex$/,""),n=t!==a,o=h.includes(a);if(!(a in(n?IDBIndex:IDBObjectStore).prototype)||!o&&!w.includes(a))return;const r=async function(e,...t){const r=this.transaction(e,o?"readwrite":"readonly");let s=r.store;return n&&(s=s.index(t.shift())),(await Promise.all([s[a](...t),o&&r.done]))[0]};return m.set(t,r),r}i(e=>({...e,get:(t,a,n)=>g(t,a)||e.get(t,a,n),has:(t,a)=>!!g(t,a)||e.has(t,a)}));const k=["continue","continuePrimaryKey","advance"],y={},b=new WeakMap,f=new WeakMap,I={get(e,t){if(!k.includes(t))return e[t];let a=y[t];return a||(a=y[t]=function(...e){b.set(this,f.get(this)[t](...e))}),a}};async function*x(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const a=new Proxy(t,I);for(f.set(a,t),r.set(a,l(t));t;)yield a,t=await(b.get(a)||t.continue()),b.delete(a)}function p(t,a){return a===Symbol.asyncIterator&&e(t,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===a&&e(t,[IDBIndex,IDBObjectStore])}i(e=>({...e,get:(t,a,n)=>p(t,a)?x:e.get(t,a,n),has:(t,a)=>p(t,a)||e.has(t,a)}));const D=64*Uint8Array.BYTES_PER_ELEMENT,B="p2party";async function S(){return function(e,t,{blocked:a,upgrade:n,blocking:o,terminated:r}={}){const s=indexedDB.open(e,t),i=d(s);return n&&s.addEventListener("upgradeneeded",e=>{n(d(s.result),e.oldVersion,e.newVersion,d(s.transaction),e)}),a&&s.addEventListener("blocked",e=>a(e.oldVersion,e.newVersion,e)),i.then(e=>{r&&e.addEventListener("close",()=>r()),o&&e.addEventListener("versionchange",e=>o(e.oldVersion,e.newVersion,e))}).catch(()=>{}),i}(B,16,{upgrade(e,t,a,n){if(e.objectStoreNames.contains("addressBook")){const e=n.objectStore("addressBook");e.indexNames.contains("username")||e.createIndex("username","username",{unique:!1}),e.indexNames.contains("peerId")||e.createIndex("peerId","peerId",{unique:!0}),e.indexNames.contains("peerPublicKey")||e.createIndex("peerPublicKey","peerPublicKey",{unique:!0})}else{const t=e.createObjectStore("addressBook",{keyPath:["peerId"]});t.createIndex("username","username",{unique:!1}),t.createIndex("peerId","peerId",{unique:!0}),t.createIndex("peerPublicKey","peerPublicKey",{unique:!0})}if(e.objectStoreNames.contains("blacklist")){const e=n.objectStore("blacklist");e.indexNames.contains("username")||e.createIndex("username","username",{unique:!1}),e.indexNames.contains("peerId")||e.createIndex("peerId","peerId",{unique:!0}),e.indexNames.contains("peerPublicKey")||e.createIndex("peerPublicKey","peerPublicKey",{unique:!0})}else{const t=e.createObjectStore("blacklist",{keyPath:["peerId"]});t.createIndex("username","username",{unique:!1}),t.createIndex("peerId","peerId",{unique:!0}),t.createIndex("peerPublicKey","peerPublicKey",{unique:!0})}if(e.objectStoreNames.contains("uniqueRoom")){const e=n.objectStore("uniqueRoom");e.indexNames.contains("roomUrl")||e.createIndex("roomUrl","roomUrl",{unique:!0}),e.indexNames.contains("roomId")||e.createIndex("roomId","roomId",{unique:!0})}else{const t=e.createObjectStore("uniqueRoom",{keyPath:["roomId"]});t.createIndex("roomUrl","roomUrl",{unique:!0}),t.createIndex("roomId","roomId",{unique:!0})}if(e.objectStoreNames.contains("messageData")){const e=n.objectStore("messageData");e.indexNames.contains("roomId")||e.createIndex("roomId","roomId",{unique:!1}),e.indexNames.contains("hash")||e.createIndex("hash","hash",{unique:!1}),e.indexNames.contains("merkleRoot")||e.createIndex("merkleRoot","merkleRoot",{unique:!0}),e.indexNames.contains("fromPeerId")||e.createIndex("fromPeerId","fromPeerId",{unique:!1})}else{const t=e.createObjectStore("messageData",{keyPath:["timestamp","roomId","merkleRoot"]});t.createIndex("roomId","roomId",{unique:!1}),t.createIndex("hash","hash",{unique:!1}),t.createIndex("merkleRoot","merkleRoot",{unique:!0}),t.createIndex("fromPeerId","fromPeerId",{unique:!1})}if(e.objectStoreNames.contains("chunks")){const e=n.objectStore("chunks");e.indexNames.contains("merkleRoot")||e.createIndex("merkleRoot","merkleRoot",{unique:!1}),e.indexNames.contains("hash")||e.createIndex("hash","hash",{unique:!1})}else{const t=e.createObjectStore("chunks",{keyPath:["merkleRoot","chunkIndex"]});t.createIndex("merkleRoot","merkleRoot",{unique:!1}),t.createIndex("hash","hash",{unique:!1})}if(e.objectStoreNames.contains("newChunks")){const e=n.objectStore("newChunks");e.indexNames.contains("hash")||e.createIndex("hash","hash",{unique:!1}),e.indexNames.contains("merkleRoot")||e.createIndex("merkleRoot","merkleRoot",{unique:!1}),e.indexNames.contains("realChunkHash")||e.createIndex("realChunkHash","realChunkHash",{unique:!0})}else{const t=e.createObjectStore("newChunks",{keyPath:["hash","chunkIndex"]});t.createIndex("hash","hash",{unique:!1}),t.createIndex("merkleRoot","merkleRoot",{unique:!1}),t.createIndex("realChunkHash","realChunkHash",{unique:!0})}if(e.objectStoreNames.contains("sendQueue")){const e=n.objectStore("sendQueue");e.indexNames.contains("labelPeer")||e.createIndex("labelPeer",["label","toPeerId"],{unique:!1})}else{e.createObjectStore("sendQueue",{keyPath:["position","label","toPeerId"]}).createIndex("labelPeer",["label","toPeerId"],{unique:!1})}}})}async function R(){await function(e,{blocked:t}={}){const a=indexedDB.deleteDatabase(e);return t&&a.addEventListener("blocked",e=>t(e.oldVersion,e)),d(a).then(()=>{})}(B,{blocked(){console.error("DB deletion BLOCKED")}})}onmessage=async e=>{const t=e.data,{id:a,method:n}=t;try{let e;switch(n){case"getDBAddressBookEntry":e=await async function(e,t){if(!e&&!t)return;if(e&&e.length<10&&!t)return;if(t&&64!==t.length&&!e)return;const a=await S();try{const n=a.transaction("addressBook","readonly"),o=e?n.objectStore("addressBook").index("peerId"):n.objectStore("addressBook").index("peerPublicKey"),r=e?await o.get(e):await o.get(t);return await n.done,a.close(),r?{username:r.username,peerId:r.peerId,peerPublicKey:r.peerPublicKey}:void 0}catch(e){return void a.close()}}(...t.args);break;case"getAllDBAddressBookEntries":e=await async function(){try{const e=await S(),t=await e.getAll("addressBook");return e.close(),t}catch(e){return[]}}(...t.args);break;case"setDBAddressBookEntry":e=await async function(e,t,a){try{const n=await S(),o=n.transaction(["addressBook"],"readwrite"),r=o.objectStore("addressBook"),s=r.index("peerId"),i=r.index("peerPublicKey"),c=await s.get(t),u=await i.get(a);(!c&&!u||c&&!u||!c&&u)&&await r.put({username:e,peerId:t,peerPublicKey:a,dateAdded:Date.now()}),await o.done,n.close()}catch(e){console.error(e)}}(...t.args);break;case"deleteDBAddressBookEntry":e=await async function(e,t,a){const n=!e||0===e.length,o=!t||t.length<10,r=!a||64!==a.length;if(n&&o&&r)throw new Error("Cannot delete address book with no data");let s=t??"";try{const n=await S(),i=n.transaction("addressBook","readwrite"),c=i.objectStore("addressBook");if(o)if(r){const t=c.index("username"),a=await t.getKey(e);if(a){const n=await t.get(e);s=n?.peerId??"",await c.delete(a)}}else{const e=c.index("peerPublicKey"),t=await e.getKey(a);if(t){const n=await e.get(a);s=n?.peerId??"",await c.delete(t)}}else{const e=c.index("peerId"),a=await e.getKey(t);a&&await c.delete(a)}await i.done,n.close()}catch{}return s}(...t.args);break;case"getDBPeerIsBlacklisted":e=await async function(e,t){if(!e&&!t)return!1;if(e&&e.length<10&&!t)return!1;if(t&&64!==t.length&&!e)return!1;try{const a=await S(),n=a.transaction("blacklist","readonly"),o=e?n.objectStore("blacklist").index("peerId"):n.objectStore("blacklist").index("peerPublicKey"),r=e?await o.get(e):await o.get(t);return await n.done,a.close(),!!r}catch(e){return!1}}(...t.args);break;case"getAllDBBlacklisted":e=await async function(){const e=await S();try{const t=await e.getAll("blacklist");return e.close(),t}catch(t){return e.close(),[]}}(...t.args);break;case"setDBPeerInBlacklist":e=await async function(e,t){try{const a=await S(),n=a.transaction(["blacklist"],"readwrite"),o=n.objectStore("blacklist"),r=o.index("peerId"),s=o.index("peerPublicKey"),i=await r.get(e),c=await s.get(t);(!i&&!c||i&&!c||!i&&c)&&await o.put({peerId:e,peerPublicKey:t,dateAdded:Date.now()}),await n.done,a.close()}catch(e){console.error(e)}}(...t.args);break;case"deleteDBPeerFromBlacklist":e=await async function(e,t){const a=!e||e.length<10,n=!t||64!==t.length;if(a&&n)throw new Error("Cannot delete blacklisted with no data");try{const n=await S(),o=n.transaction("blacklist","readwrite"),r=o.objectStore("blacklist");if(a){const e=r.index("peerPublicKey"),a=await e.getKey(t);a&&await r.delete(a)}else{const t=r.index("peerId"),a=await t.getKey(e);a&&await r.delete(a)}await o.done,n.close()}catch(e){console.error(e)}}(...t.args);break;case"getAllDBUniqueRooms":e=await async function(){const e=await S();try{const t=await e.getAll("uniqueRoom");return e.close(),t}catch(t){return e.close(),[]}}(...t.args);break;case"setDBUniqueRoom":e=await async function(e,t){try{const a=await S(),n=a.transaction(["uniqueRoom"],"readwrite"),o=n.objectStore("uniqueRoom"),r=o.index("roomUrl"),s=o.index("roomId"),i=await r.get(e),c=await s.get(t);if(!i&&!c){const a=Date.now();await o.put({roomId:t,roomUrl:e,messageCount:0,lastMessageMerkleRoot:"",createdAt:a,updatedAt:a})}await n.done,a.close()}catch(e){console.error(e)}}(...t.args);break;case"getDBMessageData":e=await async function(e,t){try{const a=await S(),n=a.transaction(["messageData"],"readonly"),o=n.objectStore("messageData"),r=o.index("merkleRoot"),s=o.index("hash");if(e&&e.length===2*D){const o=await r.get(e);if(o)return await n.done,a.close(),o;if(t&&t.length===2*D){const e=await s.get(t);return await n.done,a.close(),e}return await n.done,void a.close()}if(t&&t.length===2*D){const e=await s.get(t);return await n.done,a.close(),e}return await n.done,void a.close()}catch(e){return void console.error(e)}}(...t.args);break;case"getDBRoomMessageData":e=await async function(e){const t=await S(),a=await t.getAllFromIndex("messageData","roomId",e);t.close();const n=a.length,o=[];for(let t=0;t<n;t++)o.push({roomId:e,merkleRoot:a[t].merkleRoot,hash:a[t].hash,fromPeerId:a[t].fromPeerId,filename:a[t].filename,messageType:a[t].messageType,savedSize:a[t].savedSize,totalSize:a[t].totalSize,channelLabel:a[t].channelLabel,timestamp:a[t].timestamp});return o}(...t.args);break;case"setDBRoomMessageData":e=await async function(e,t,a,n,o,r,s,i,c,u){try{const d=await S(),l=d.transaction(["messageData","uniqueRoom"],"readwrite"),w=l.objectStore("messageData"),h=await w.index("merkleRoot").get(t),m=h?.savedSize??0;try{await w.put({roomId:e,timestamp:u,merkleRoot:t,hash:a,fromPeerId:n,filename:i,messageType:s,savedSize:m!==r?o+m:o,totalSize:r,channelLabel:c})}catch(e){throw await l.done,d.close(),e}const g=l.objectStore("uniqueRoom"),k=await g.index("roomId").get(e);if(k&&k.lastMessageMerkleRoot!==t)try{await g.put({...k,lastMessageMerkleRoot:t,messageCount:k.messageCount+1,updatedAt:Date.now()})}catch(e){throw await l.done,d.close(),e}await l.done,d.close()}catch(e){throw console.error(e),e}}(...t.args);break;case"getDBChunk":e=await async function(e,t){const a=await S(),n=await a.get("chunks",[e,t]);return a.close(),n?.data}(...t.args);break;case"existsDBChunk":e=await async function(e,t){const a=await S(),n=await a.count("chunks",[e,t]);return a.close(),n>0}(...t.args);break;case"getDBNewChunk":e=await async function(e,t){try{const a=await S(),n=t??-1;if(n>-1){const t=await a.get("newChunks",[e,n]);return a.close(),t}{const t=a.transaction("newChunks"),n=t.objectStore("newChunks").index("realChunkHash"),o=await n.get(e);return await t.done,a.close(),o}}catch(e){return void console.error(e)}}(...t.args);break;case"existsDBNewChunk":e=await async function(e,t){const a=await S(),n=await a.count("newChunks",[e,t]);return a.close(),n>0}(...t.args);break;case"getDBSendQueue":e=await async function(e,t,a){const n=await S();if(a){const o=await n.get("sendQueue",[a,e,t]);return n.close(),o?[o]:[]}const o=n.transaction("sendQueue","readonly").objectStore("sendQueue").index("labelPeer"),r=IDBKeyRange.only([e,t]),s=await o.getAll(r);return n.close(),s}(...t.args);break;case"getDBAllChunks":e=await async function(e,t){try{const a=await S(),n=a.transaction("chunks","readonly"),o=n.objectStore("chunks"),r=o.index("hash"),s=o.index("merkleRoot");if(e&&e.length===2*D){const t=await s.getAll(e);return 0===t.length?(await n.done,a.close(),[]):(await n.done,a.close(),t)}if(t&&t.length===2*D){const e=await r.getAll(t);return await n.done,a.close(),e}return await n.done,a.close(),[]}catch(e){return console.error(e),[]}}(...t.args);break;case"getDBAllChunksCount":e=await async function(e,t){try{const a=await S(),n=a.transaction(["chunks"],"readonly"),o=n.objectStore("chunks"),r=o.index("hash"),s=o.index("merkleRoot");if(t&&t.length===2*D){const o=await r.count(t);if(0===o){if(e&&e.length===2*D){const t=await s.count(e);return await n.done,a.close(),t}return await n.done,a.close(),0}return await n.done,a.close(),o}if(e&&e.length===2*D){const t=await s.count(e);return await n.done,a.close(),t}return await n.done,a.close(),0}catch(e){return 0}}(...t.args);break;case"setDBChunk":e=await async function(e){const t=await S();await t.add("chunks",e),t.close()}(...t.args);break;case"getDBAllNewChunks":e=await async function(e,t){if(!e&&!t)return[];if(e?.length!==2*D&&t?.length!==2*D)return[];const a=await S();if((e?await a.countFromIndex("newChunks","hash",e):await a.countFromIndex("newChunks","merkleRoot",t))>0){const n=e?await a.getAllFromIndex("newChunks","hash",e):await a.getAllFromIndex("newChunks","merkleRoot",t);return a.close(),n}{const n=a.transaction("newChunks","readonly").objectStore("newChunks"),o=e?n.index("hash"):n.index("merkleRoot"),r=e?IDBKeyRange.only(e):IDBKeyRange.only(t),s=await o.getAll(r);return a.close(),s}}(...t.args);break;case"getDBAllNewChunksCount":e=await async function(e){const t=await S(),a=await t.countFromIndex("newChunks","hash",e);return t.close(),a}(...t.args);break;case"setDBNewChunk":e=await async function(e){const t=await S();await t.put("newChunks",e),t.close()}(...t.args);break;case"setDBSendQueue":e=await async function(e){const t=await S();await t.put("sendQueue",e),t.close()}(...t.args);break;case"countDBSendQueue":e=await async function(e,t){const a=await S(),n=a.transaction("sendQueue","readonly").objectStore("sendQueue").index("labelPeer"),o=IDBKeyRange.only([e,t]),r=await n.count(o);return a.close(),r}(...t.args);break;case"deleteDBChunk":e=await async function(e,t){try{const a=await S(),n=a.transaction("chunks","readwrite"),o=n.objectStore("chunks");if(t){const a=IDBKeyRange.only([e,t]);await o.delete(a)}else{const t=o.index("hash"),a=await t.getAllKeys(e),n=a.length;if(0===n){const t=o.index("merkleRoot"),a=await t.getAllKeys(e),n=a.length;for(let e=0;e<n;e++)await o.delete(a[e])}else for(let e=0;e<n;e++)await o.delete(a[e])}await n.done,a.close()}catch(e){}}(...t.args);break;case"deleteDBNewChunk":e=await async function(e,t,a,n){try{const o=await S(),r=o.transaction("newChunks","readwrite"),s=r.objectStore("newChunks");if(e){const t=s.index("merkleRoot"),a=await t.getAllKeys(e),n=a.length;for(let e=0;e<n;e++)await s.delete(a[e])}else if(a&&n)await s.delete([a,n]);else if(a){const e=s.index("hash"),t=await e.getAllKeys(a),n=t.length;for(let e=0;e<n;e++)await s.delete(t[e])}else if(t){const e=s.index("realChunkHash"),a=await e.getKey(t);a&&await s.delete(a)}await r.done,o.close()}catch(e){console.error(e)}}(...t.args);break;case"deleteDBMessageData":e=await async function(e){try{const t=await S(),a=t.transaction(["messageData","uniqueRoom"],"readwrite"),n=a.objectStore("messageData"),o=a.objectStore("uniqueRoom"),r=n.index("merkleRoot"),s=await r.getAllKeys(e),i=s.length;let c="";for(let e=0;e<i;e++){if(0===e||0===c.length){const t=await n.get(s[e]);c=t?.roomId??""}await n.delete(s[e])}if(c.length>0){const e=o.index("roomId"),t=await e.get(c);if(t){const e=n.index("roomId"),a=await e.getAllKeys(c),r=a.length,s=r>0?await n.get(a[r-1]):void 0;await o.put({...t,messageCount:t.messageCount>0?t.messageCount-1:0,updatedAt:s?.timestamp??Date.now(),lastMessageMerkleRoot:s?.merkleRoot??""})}}await a.done,t.close()}catch(e){}}(...t.args);break;case"deleteDBUniqueRoom":e=await async function(e){try{const t=await S(),a=t.transaction("uniqueRoom","readwrite"),n=a.objectStore("uniqueRoom"),o=n.index("roomId"),r=await o.getKey(e);r&&await n.delete(r),await a.done,t.close()}catch(e){}}(...t.args);break;case"deleteDBSendQueue":e=await async function(e,t,a){try{const n=await S();if(a)await n.delete("sendQueue",[a,e,t]);else{const a=IDBKeyRange.only([e,t]);await n.delete("sendQueue",a)}n.close()}catch(e){}}(...t.args);break;case"deleteDB":e=await R();break;default:return void postMessage({id:a,error:"Method not found"})}postMessage({id:a,result:e})}catch(e){postMessage({id:a,error:String(e)})}};
|
|
1
|
+
const e=(e,t)=>t.some(t=>e instanceof t);let t,a;const n=new WeakMap,o=new WeakMap,r=new WeakMap;let s={get(e,t,a){if(e instanceof IDBTransaction){if("done"===t)return n.get(e);if("store"===t)return a.objectStoreNames[1]?void 0:a.objectStore(a.objectStoreNames[0])}return d(e[t])},set:(e,t,a)=>(e[t]=a,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function i(e){s=e(s)}function c(e){return(a||(a=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(l(this),t),d(this.request)}:function(...t){return d(e.apply(l(this),t))}}function u(a){return"function"==typeof a?c(a):(a instanceof IDBTransaction&&function(e){if(n.has(e))return;const t=new Promise((t,a)=>{const n=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",r),e.removeEventListener("abort",r)},o=()=>{t(),n()},r=()=>{a(e.error||new DOMException("AbortError","AbortError")),n()};e.addEventListener("complete",o),e.addEventListener("error",r),e.addEventListener("abort",r)});n.set(e,t)}(a),e(a,t||(t=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(a,s):a)}function d(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,a)=>{const n=()=>{e.removeEventListener("success",o),e.removeEventListener("error",r)},o=()=>{t(d(e.result)),n()},r=()=>{a(e.error),n()};e.addEventListener("success",o),e.addEventListener("error",r)});return r.set(t,e),t}(e);if(o.has(e))return o.get(e);const t=u(e);return t!==e&&(o.set(e,t),r.set(t,e)),t}const l=e=>r.get(e);const w=["get","getKey","getAll","getAllKeys","count"],h=["put","add","delete","clear"],m=new Map;function g(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(m.get(t))return m.get(t);const a=t.replace(/FromIndex$/,""),n=t!==a,o=h.includes(a);if(!(a in(n?IDBIndex:IDBObjectStore).prototype)||!o&&!w.includes(a))return;const r=async function(e,...t){const r=this.transaction(e,o?"readwrite":"readonly");let s=r.store;return n&&(s=s.index(t.shift())),(await Promise.all([s[a](...t),o&&r.done]))[0]};return m.set(t,r),r}i(e=>({...e,get:(t,a,n)=>g(t,a)||e.get(t,a,n),has:(t,a)=>!!g(t,a)||e.has(t,a)}));const k=["continue","continuePrimaryKey","advance"],y={},b=new WeakMap,f=new WeakMap,I={get(e,t){if(!k.includes(t))return e[t];let a=y[t];return a||(a=y[t]=function(...e){b.set(this,f.get(this)[t](...e))}),a}};async function*x(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const a=new Proxy(t,I);for(f.set(a,t),r.set(a,l(t));t;)yield a,t=await(b.get(a)||t.continue()),b.delete(a)}function p(t,a){return a===Symbol.asyncIterator&&e(t,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===a&&e(t,[IDBIndex,IDBObjectStore])}i(e=>({...e,get:(t,a,n)=>p(t,a)?x:e.get(t,a,n),has:(t,a)=>p(t,a)||e.has(t,a)}));const D=64*Uint8Array.BYTES_PER_ELEMENT,B="p2party";async function S(){return function(e,t,{blocked:a,upgrade:n,blocking:o,terminated:r}={}){const s=indexedDB.open(e,t),i=d(s);return n&&s.addEventListener("upgradeneeded",e=>{n(d(s.result),e.oldVersion,e.newVersion,d(s.transaction),e)}),a&&s.addEventListener("blocked",e=>a(e.oldVersion,e.newVersion,e)),i.then(e=>{r&&e.addEventListener("close",()=>r()),o&&e.addEventListener("versionchange",e=>o(e.oldVersion,e.newVersion,e))}).catch(()=>{}),i}(B,16,{upgrade(e,t,a,n){if(e.objectStoreNames.contains("addressBook")){const e=n.objectStore("addressBook");e.indexNames.contains("username")||e.createIndex("username","username",{unique:!1}),e.indexNames.contains("peerId")||e.createIndex("peerId","peerId",{unique:!0}),e.indexNames.contains("peerPublicKey")||e.createIndex("peerPublicKey","peerPublicKey",{unique:!0})}else{const t=e.createObjectStore("addressBook",{keyPath:["peerId"]});t.createIndex("username","username",{unique:!1}),t.createIndex("peerId","peerId",{unique:!0}),t.createIndex("peerPublicKey","peerPublicKey",{unique:!0})}if(e.objectStoreNames.contains("blacklist")){const e=n.objectStore("blacklist");e.indexNames.contains("username")||e.createIndex("username","username",{unique:!1}),e.indexNames.contains("peerId")||e.createIndex("peerId","peerId",{unique:!0}),e.indexNames.contains("peerPublicKey")||e.createIndex("peerPublicKey","peerPublicKey",{unique:!0})}else{const t=e.createObjectStore("blacklist",{keyPath:["peerId"]});t.createIndex("username","username",{unique:!1}),t.createIndex("peerId","peerId",{unique:!0}),t.createIndex("peerPublicKey","peerPublicKey",{unique:!0})}if(e.objectStoreNames.contains("uniqueRoom")){const e=n.objectStore("uniqueRoom");e.indexNames.contains("roomUrl")||e.createIndex("roomUrl","roomUrl",{unique:!0}),e.indexNames.contains("roomId")||e.createIndex("roomId","roomId",{unique:!0})}else{const t=e.createObjectStore("uniqueRoom",{keyPath:["roomId"]});t.createIndex("roomUrl","roomUrl",{unique:!0}),t.createIndex("roomId","roomId",{unique:!0})}if(e.objectStoreNames.contains("messageData")){const e=n.objectStore("messageData");e.indexNames.contains("roomId")||e.createIndex("roomId","roomId",{unique:!1}),e.indexNames.contains("hash")||e.createIndex("hash","hash",{unique:!1}),e.indexNames.contains("merkleRoot")||e.createIndex("merkleRoot","merkleRoot",{unique:!0}),e.indexNames.contains("fromPeerId")||e.createIndex("fromPeerId","fromPeerId",{unique:!1})}else{const t=e.createObjectStore("messageData",{keyPath:["timestamp","roomId","merkleRoot"]});t.createIndex("roomId","roomId",{unique:!1}),t.createIndex("hash","hash",{unique:!1}),t.createIndex("merkleRoot","merkleRoot",{unique:!0}),t.createIndex("fromPeerId","fromPeerId",{unique:!1})}if(e.objectStoreNames.contains("chunks")){const e=n.objectStore("chunks");e.indexNames.contains("merkleRoot")||e.createIndex("merkleRoot","merkleRoot",{unique:!1}),e.indexNames.contains("hash")||e.createIndex("hash","hash",{unique:!1})}else{const t=e.createObjectStore("chunks",{keyPath:["merkleRoot","chunkIndex"]});t.createIndex("merkleRoot","merkleRoot",{unique:!1}),t.createIndex("hash","hash",{unique:!1})}if(e.objectStoreNames.contains("newChunks")){const e=n.objectStore("newChunks");e.indexNames.contains("hash")||e.createIndex("hash","hash",{unique:!1}),e.indexNames.contains("merkleRoot")||e.createIndex("merkleRoot","merkleRoot",{unique:!1}),e.indexNames.contains("realChunkHash")||e.createIndex("realChunkHash","realChunkHash",{unique:!0})}else{const t=e.createObjectStore("newChunks",{keyPath:["hash","chunkIndex"]});t.createIndex("hash","hash",{unique:!1}),t.createIndex("merkleRoot","merkleRoot",{unique:!1}),t.createIndex("realChunkHash","realChunkHash",{unique:!0})}if(e.objectStoreNames.contains("sendQueue")){const e=n.objectStore("sendQueue");e.indexNames.contains("labelPeer")||e.createIndex("labelPeer",["label","toPeerId"],{unique:!1})}else{e.createObjectStore("sendQueue",{keyPath:["position","label","toPeerId"]}).createIndex("labelPeer",["label","toPeerId"],{unique:!1})}}})}async function R(){await function(e,{blocked:t}={}){const a=indexedDB.deleteDatabase(e);return t&&a.addEventListener("blocked",e=>t(e.oldVersion,e)),d(a).then(()=>{})}(B,{blocked(){console.error("DB deletion BLOCKED")}})}onmessage=async e=>{const t=e.data,{id:a,method:n}=t;try{let e;switch(n){case"getDBAddressBookEntry":e=await async function(e,t){if(!e&&!t)return;if(e&&e.length<10&&!t)return;if(t&&64!==t.length&&!e)return;const a=await S();try{const n=a.transaction("addressBook","readonly"),o=e?n.objectStore("addressBook").index("peerId"):n.objectStore("addressBook").index("peerPublicKey"),r=e?await o.get(e):await o.get(t);return await n.done,a.close(),r?{username:r.username,peerId:r.peerId,peerPublicKey:r.peerPublicKey}:void 0}catch(e){return void a.close()}}(...t.args);break;case"getAllDBAddressBookEntries":e=await async function(){try{const e=await S(),t=await e.getAll("addressBook");return e.close(),t}catch(e){return[]}}(...t.args);break;case"setDBAddressBookEntry":e=await async function(e,t,a){try{const n=await S(),o=n.transaction(["addressBook"],"readwrite"),r=o.objectStore("addressBook"),s=r.index("peerId"),i=r.index("peerPublicKey"),c=await s.get(t),u=await i.get(a);(!c&&!u||c&&!u||!c&&u)&&await r.put({username:e,peerId:t,peerPublicKey:a,dateAdded:Date.now()}),await o.done,n.close()}catch(e){console.error(e)}}(...t.args);break;case"deleteDBAddressBookEntry":e=await async function(e,t,a){const n=!e||0===e.length,o=!t||t.length<10,r=!a||64!==a.length;if(n&&o&&r)throw new Error("Cannot delete address book with no data");let s=t??"";try{const n=await S(),i=n.transaction("addressBook","readwrite"),c=i.objectStore("addressBook");if(o)if(r){const t=c.index("username"),a=await t.getKey(e);if(a){const n=await t.get(e);s=n?.peerId??"",await c.delete(a)}}else{const e=c.index("peerPublicKey"),t=await e.getKey(a);if(t){const n=await e.get(a);s=n?.peerId??"",await c.delete(t)}}else{const e=c.index("peerId"),a=await e.getKey(t);a&&await c.delete(a)}await i.done,n.close()}catch{}return s}(...t.args);break;case"getDBPeerIsBlacklisted":e=await async function(e,t){if(!e&&!t)return!1;if(e&&e.length<10&&!t)return!1;if(t&&64!==t.length&&!e)return!1;try{const a=await S(),n=a.transaction("blacklist","readonly"),o=e?n.objectStore("blacklist").index("peerId"):n.objectStore("blacklist").index("peerPublicKey"),r=e?await o.get(e):await o.get(t);return await n.done,a.close(),!!r}catch(e){return!1}}(...t.args);break;case"getAllDBBlacklisted":e=await async function(){const e=await S();try{const t=await e.getAll("blacklist");return e.close(),t}catch(t){return e.close(),[]}}(...t.args);break;case"setDBPeerInBlacklist":e=await async function(e,t){try{const a=await S(),n=a.transaction(["blacklist"],"readwrite"),o=n.objectStore("blacklist"),r=o.index("peerId"),s=o.index("peerPublicKey"),i=await r.get(e),c=await s.get(t);(!i&&!c||i&&!c||!i&&c)&&await o.put({peerId:e,peerPublicKey:t,dateAdded:Date.now()}),await n.done,a.close()}catch(e){console.error(e)}}(...t.args);break;case"deleteDBPeerFromBlacklist":e=await async function(e,t){const a=!e||e.length<10,n=!t||64!==t.length;if(a&&n)throw new Error("Cannot delete blacklisted with no data");try{const n=await S(),o=n.transaction("blacklist","readwrite"),r=o.objectStore("blacklist");if(a){const e=r.index("peerPublicKey"),a=await e.getKey(t);a&&await r.delete(a)}else{const t=r.index("peerId"),a=await t.getKey(e);a&&await r.delete(a)}await o.done,n.close()}catch(e){console.error(e)}}(...t.args);break;case"getAllDBUniqueRooms":e=await async function(){const e=await S();try{const t=await e.getAll("uniqueRoom");return e.close(),t}catch(t){return e.close(),[]}}(...t.args);break;case"setDBUniqueRoom":e=await async function(e,t){try{const a=await S(),n=a.transaction(["uniqueRoom"],"readwrite"),o=n.objectStore("uniqueRoom"),r=o.index("roomUrl"),s=o.index("roomId"),i=await r.get(e),c=await s.get(t);if(!i&&!c){const a=Date.now();await o.put({roomId:t,roomUrl:e,messageCount:0,lastMessageMerkleRoot:"",createdAt:a,updatedAt:a})}await n.done,a.close()}catch(e){console.error(e)}}(...t.args);break;case"getDBMessageData":e=await async function(e,t){try{const a=await S(),n=a.transaction(["messageData"],"readonly"),o=n.objectStore("messageData"),r=o.index("merkleRoot"),s=o.index("hash");if(e&&e.length===2*D){const o=await r.get(e);if(o)return await n.done,a.close(),o;if(t&&t.length===2*D){const e=await s.get(t);return await n.done,a.close(),e}return await n.done,void a.close()}if(t&&t.length===2*D){const e=await s.get(t);return await n.done,a.close(),e}return await n.done,void a.close()}catch(e){return void console.error(e)}}(...t.args);break;case"getDBRoomMessageData":e=await async function(e){const t=await S(),a=await t.getAllFromIndex("messageData","roomId",e);t.close();const n=a.length,o=[];for(let t=0;t<n;t++)o.push({roomId:e,merkleRoot:a[t].merkleRoot,hash:a[t].hash,fromPeerId:a[t].fromPeerId,filename:a[t].filename,messageType:a[t].messageType,savedSize:a[t].savedSize,totalSize:a[t].totalSize,channelLabel:a[t].channelLabel,timestamp:a[t].timestamp});return o}(...t.args);break;case"setDBRoomMessageData":e=await async function(e,t,a,n,o,r,s,i,c,u){try{const d=await S(),l=d.transaction(["messageData","uniqueRoom"],"readwrite"),w=l.objectStore("messageData"),h=await w.index("merkleRoot").get(t),m=h?.savedSize??0;try{await w.put({roomId:e,timestamp:u,merkleRoot:t,hash:a,fromPeerId:n,filename:i,messageType:s,savedSize:m!==r?o+m:o,totalSize:r,channelLabel:c})}catch(e){throw await l.done,d.close(),e}const g=l.objectStore("uniqueRoom"),k=await g.index("roomId").get(e);if(k&&k.lastMessageMerkleRoot!==t)try{await g.put({...k,lastMessageMerkleRoot:t,messageCount:k.messageCount+1,updatedAt:Date.now()})}catch(e){throw await l.done,d.close(),e}await l.done,d.close()}catch(e){throw console.error(e),e}}(...t.args);break;case"getDBChunk":e=await async function(e,t){const a=await S(),n=await a.get("chunks",[e,t]);return a.close(),n?.data}(...t.args);break;case"existsDBChunk":e=await async function(e,t){const a=await S(),n=await a.count("chunks",[e,t]);return a.close(),n>0}(...t.args);break;case"getDBNewChunk":e=await async function(e,t){try{const a=await S(),n=t??-1;if(n>-1){const t=await a.get("newChunks",[e,n]);return a.close(),t}{const t=a.transaction("newChunks"),n=t.objectStore("newChunks").index("realChunkHash"),o=await n.get(e);return await t.done,a.close(),o}}catch(e){return void console.error(e)}}(...t.args);break;case"existsDBNewChunk":e=await async function(e,t){const a=await S(),n=await a.count("newChunks",[e,t]);return a.close(),n>0}(...t.args);break;case"getDBSendQueue":e=await async function(e,t,a){const n=await S();if(a){const o=await n.get("sendQueue",[a,e,t]);return n.close(),o?[o]:[]}const o=n.transaction("sendQueue","readonly").objectStore("sendQueue").index("labelPeer"),r=IDBKeyRange.only([e,t]),s=await o.getAll(r);return n.close(),s}(...t.args);break;case"getDBAllChunks":e=await async function(e,t){try{const a=await S(),n=a.transaction("chunks","readonly"),o=n.objectStore("chunks"),r=o.index("hash"),s=o.index("merkleRoot");if(e&&e.length===2*D){const t=await s.getAll(e);return 0===t.length?(await n.done,a.close(),[]):(await n.done,a.close(),t)}if(t&&t.length===2*D){const e=await r.getAll(t);return await n.done,a.close(),e}return await n.done,a.close(),[]}catch(e){return console.error(e),[]}}(...t.args);break;case"getDBAllChunksCount":e=await async function(e,t){try{const a=await S(),n=a.transaction(["chunks"],"readonly"),o=n.objectStore("chunks"),r=o.index("hash"),s=o.index("merkleRoot");if(t&&t.length===2*D){const o=await r.count(t);if(0===o){if(e&&e.length===2*D){const t=await s.count(e);return await n.done,a.close(),t}return await n.done,a.close(),0}return await n.done,a.close(),o}if(e&&e.length===2*D){const t=await s.count(e);return await n.done,a.close(),t}return await n.done,a.close(),0}catch(e){return 0}}(...t.args);break;case"setDBChunk":e=await async function(e){const t=await S();try{await t.add("chunks",e)}catch(e){}t.close()}(...t.args);break;case"getDBAllNewChunks":e=await async function(e,t){if(!e&&!t)return[];if(e?.length!==2*D&&t?.length!==2*D)return[];const a=await S();if((e?await a.countFromIndex("newChunks","hash",e):await a.countFromIndex("newChunks","merkleRoot",t))>0){const n=e?await a.getAllFromIndex("newChunks","hash",e):await a.getAllFromIndex("newChunks","merkleRoot",t);return a.close(),n}{const n=a.transaction("newChunks","readonly").objectStore("newChunks"),o=e?n.index("hash"):n.index("merkleRoot"),r=e?IDBKeyRange.only(e):IDBKeyRange.only(t),s=await o.getAll(r);return a.close(),s}}(...t.args);break;case"getDBAllNewChunksCount":e=await async function(e){const t=await S(),a=await t.countFromIndex("newChunks","hash",e);return t.close(),a}(...t.args);break;case"setDBNewChunk":e=await async function(e){const t=await S();await t.put("newChunks",e),t.close()}(...t.args);break;case"setDBSendQueue":e=await async function(e){const t=await S();await t.put("sendQueue",e),t.close()}(...t.args);break;case"countDBSendQueue":e=await async function(e,t){const a=await S(),n=a.transaction("sendQueue","readonly").objectStore("sendQueue").index("labelPeer"),o=IDBKeyRange.only([e,t]),r=await n.count(o);return a.close(),r}(...t.args);break;case"deleteDBChunk":e=await async function(e,t){try{const a=await S(),n=a.transaction("chunks","readwrite"),o=n.objectStore("chunks");if(t){const a=IDBKeyRange.only([e,t]);await o.delete(a)}else{const t=o.index("hash"),a=await t.getAllKeys(e),n=a.length;if(0===n){const t=o.index("merkleRoot"),a=await t.getAllKeys(e),n=a.length;for(let e=0;e<n;e++)await o.delete(a[e])}else for(let e=0;e<n;e++)await o.delete(a[e])}await n.done,a.close()}catch(e){}}(...t.args);break;case"deleteDBNewChunk":e=await async function(e,t,a,n){try{const o=await S(),r=o.transaction("newChunks","readwrite"),s=r.objectStore("newChunks");if(e){const t=s.index("merkleRoot"),a=await t.getAllKeys(e),n=a.length;for(let e=0;e<n;e++)await s.delete(a[e])}else if(a&&n)await s.delete([a,n]);else if(a){const e=s.index("hash"),t=await e.getAllKeys(a),n=t.length;for(let e=0;e<n;e++)await s.delete(t[e])}else if(t){const e=s.index("realChunkHash"),a=await e.getKey(t);a&&await s.delete(a)}await r.done,o.close()}catch(e){console.error(e)}}(...t.args);break;case"deleteDBMessageData":e=await async function(e){try{const t=await S(),a=t.transaction(["messageData","uniqueRoom"],"readwrite"),n=a.objectStore("messageData"),o=a.objectStore("uniqueRoom"),r=n.index("merkleRoot"),s=await r.getAllKeys(e),i=s.length;let c="";for(let e=0;e<i;e++){if(0===e||0===c.length){const t=await n.get(s[e]);c=t?.roomId??""}await n.delete(s[e])}if(c.length>0){const e=o.index("roomId"),t=await e.get(c);if(t){const e=n.index("roomId"),a=await e.getAllKeys(c),r=a.length,s=r>0?await n.get(a[r-1]):void 0;await o.put({...t,messageCount:t.messageCount>0?t.messageCount-1:0,updatedAt:s?.timestamp??Date.now(),lastMessageMerkleRoot:s?.merkleRoot??""})}}await a.done,t.close()}catch(e){}}(...t.args);break;case"deleteDBUniqueRoom":e=await async function(e){try{const t=await S(),a=t.transaction("uniqueRoom","readwrite"),n=a.objectStore("uniqueRoom"),o=n.index("roomId"),r=await o.getKey(e);r&&await n.delete(r),await a.done,t.close()}catch(e){}}(...t.args);break;case"deleteDBSendQueue":e=await async function(e,t,a){try{const n=await S();if(a)await n.delete("sendQueue",[a,e,t]);else{const a=IDBKeyRange.only([e,t]);await n.delete("sendQueue",a)}n.close()}catch(e){}}(...t.args);break;case"deleteDB":e=await R();break;default:return void postMessage({id:a,error:"Method not found"})}postMessage({id:a,result:e})}catch(e){postMessage({id:a,error:String(e)})}};
|
|
2
2
|
//# sourceMappingURL=db.worker.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MiddlewareAPI
|
|
1
|
+
import type { MiddlewareAPI } from "@reduxjs/toolkit";
|
|
2
2
|
import type { KeyPair } from "../reducers/keyPairSlice";
|
|
3
|
-
declare const handleChallenge: (keyPair: KeyPair, peerId: string, challenge: string, store: MiddlewareAPI
|
|
3
|
+
declare const handleChallenge: (keyPair: KeyPair, peerId: string, challenge: string, store: MiddlewareAPI) => Promise<void>;
|
|
4
4
|
export default handleChallenge;
|
|
5
5
|
//# sourceMappingURL=handleChallenge.d.ts.map
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { BaseQueryApi } from "@reduxjs/toolkit/query";
|
|
2
2
|
import type { IRTCPeerConnection, RTCPeerConnectionParams } from "../api/webrtc/interfaces";
|
|
3
|
-
export
|
|
3
|
+
export interface IRTCPeerConnectionParams extends RTCPeerConnectionParams {
|
|
4
|
+
peerConnections: IRTCPeerConnection[];
|
|
5
|
+
}
|
|
6
|
+
export declare const handleConnectToPeer: ({ peerId, peerPublicKey, roomId, peerConnections, rtcConfig, }: IRTCPeerConnectionParams, api: BaseQueryApi) => Promise<IRTCPeerConnection>;
|
|
4
7
|
//# sourceMappingURL=handleConnectToPeer.d.ts.map
|
|
@@ -11,5 +11,5 @@ export interface OpenChannelHelperParams {
|
|
|
11
11
|
}
|
|
12
12
|
export declare const KB64: number;
|
|
13
13
|
export declare const MAX_BUFFERED_AMOUNT: number;
|
|
14
|
-
export declare const handleOpenChannel: ({ channel, epc, roomId, dataChannels, decryptionModule, merkleModule, }: OpenChannelHelperParams, api: BaseQueryApi) => IRTCDataChannel
|
|
14
|
+
export declare const handleOpenChannel: ({ channel, epc, roomId, dataChannels, decryptionModule, merkleModule, }: OpenChannelHelperParams, api: BaseQueryApi) => Promise<IRTCDataChannel>;
|
|
15
15
|
//# sourceMappingURL=handleOpenChannel.d.ts.map
|
package/lib/index.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ export declare const p2party: {
|
|
|
84
84
|
peerPublicKey: string;
|
|
85
85
|
}[]) => Promise<void>;
|
|
86
86
|
sendMessage: (data: string | File, toChannel: string, roomId: string, percentageFilledChunk?: number, minChunks?: number, chunkSize?: number, metadataSchemaVersion?: number) => Promise<void>;
|
|
87
|
-
readMessage: (merkleRootHex
|
|
87
|
+
readMessage: (merkleRootHex: string) => Promise<{
|
|
88
88
|
message: string | Blob;
|
|
89
89
|
percentage: number;
|
|
90
90
|
size: number;
|
|
@@ -93,7 +93,7 @@ export declare const p2party: {
|
|
|
93
93
|
extension: FileExtension;
|
|
94
94
|
category: string;
|
|
95
95
|
}>;
|
|
96
|
-
cancelMessage: (channelLabel: string, merkleRoot
|
|
96
|
+
cancelMessage: (channelLabel: string, merkleRoot: string | Uint8Array) => Promise<void>;
|
|
97
97
|
deleteMessage: (merkleRoot?: string | Uint8Array, hash?: string | Uint8Array) => Promise<void>;
|
|
98
98
|
purgeIdentity: () => Promise<void>;
|
|
99
99
|
purgeRoom: (roomUrl: string) => Promise<void>;
|