copious-mail 0.0.0-stage → 0.9.1

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.
Files changed (182) hide show
  1. package/LICENSE +504 -0
  2. package/README.md +143 -2
  3. package/bin/index.js +345 -0
  4. package/client/copiousLogo.svg +123 -0
  5. package/client/hosted.html +5259 -0
  6. package/client/mail_styles.css +40 -0
  7. package/client/mikado.bundle.debug.js +1406 -0
  8. package/client/mikado.bundle.min.js +68 -0
  9. package/client/mikado.bundle.module.debug.js +1401 -0
  10. package/client/mikado.bundle.module.min.js +67 -0
  11. package/client/mikado.bundle.profiler.debug.js +1490 -0
  12. package/client/mikado.es5.debug.js +1995 -0
  13. package/client/mikado.es5.min.js +85 -0
  14. package/client/mikado.light.debug.js +535 -0
  15. package/client/mikado.light.min.js +29 -0
  16. package/client/mikado.light.module.debug.js +530 -0
  17. package/data/user_list.db +14 -0
  18. package/index.html +7242 -0
  19. package/index.js +5 -0
  20. package/jsconfig.json +32 -0
  21. package/lib/mail_repo_bridge_ops.js +1177 -0
  22. package/lib/utils.js +70 -0
  23. package/lib/websocket_con.js +249 -0
  24. package/mail_bridge.conf +10 -0
  25. package/package.json +41 -5
  26. package/svelte-src/App.svelte +2513 -0
  27. package/svelte-src/ContactGrid.svelte +98 -0
  28. package/svelte-src/FloatWindow.svelte +181 -0
  29. package/svelte-src/MessageDisplay.svelte +230 -0
  30. package/svelte-src/MessageEditor.svelte +664 -0
  31. package/svelte-src/MessageListEditor.svelte +133 -0
  32. package/svelte-src/Thing.svelte +190 -0
  33. package/svelte-src/ThingFull.svelte +117 -0
  34. package/svelte-src/ipfs_profile_proxy.js +923 -0
  35. package/svelte-src/main.js +10 -0
  36. package/svelte-src/search_box.js +69 -0
  37. package/svelte-src/utilities.js +180 -0
  38. package/test/c +28 -0
  39. package/test/copiousLogo.svg +123 -0
  40. package/test/index.html +4408 -0
  41. package/test/index.js +244 -0
  42. package/test/mail_styles.css +40 -0
  43. package/test/mikado.bundle.debug.js +1406 -0
  44. package/test/mikado.bundle.min.js +68 -0
  45. package/test/mikado.bundle.module.debug.js +1401 -0
  46. package/test/mikado.bundle.module.min.js +67 -0
  47. package/test/mikado.bundle.profiler.debug.js +1490 -0
  48. package/test/mikado.es5.debug.js +1995 -0
  49. package/test/mikado.es5.min.js +85 -0
  50. package/test/mikado.light.debug.js +535 -0
  51. package/test/mikado.light.min.js +29 -0
  52. package/test/mikado.light.module.debug.js +530 -0
  53. package/test/tpl/partial/attachment_edit.es5.js +1 -0
  54. package/test/tpl/partial/attachment_edit.html +5 -0
  55. package/test/tpl/partial/attachment_edit.js +1 -0
  56. package/test/tpl/partial/attachment_view.es5.js +1 -0
  57. package/test/tpl/partial/attachment_view.html +1 -0
  58. package/test/tpl/partial/attachment_view.js +1 -0
  59. package/test/tpl/partial/contact_list.es5.js +1 -0
  60. package/test/tpl/partial/contact_list.html +9 -0
  61. package/test/tpl/partial/contact_list.js +1 -0
  62. package/test/tpl/partial/draft_list.es5.js +1 -0
  63. package/test/tpl/partial/draft_list.html +8 -0
  64. package/test/tpl/partial/draft_list.js +1 -0
  65. package/test/tpl/partial/inbox_list.es5.js +1 -0
  66. package/test/tpl/partial/inbox_list.html +7 -0
  67. package/test/tpl/partial/inbox_list.js +1 -0
  68. package/test/tpl/partial/notify_list.es5.js +1 -0
  69. package/test/tpl/partial/notify_list.html +8 -0
  70. package/test/tpl/partial/notify_list.js +1 -0
  71. package/test/tpl/partial/sent_list.es5.js +1 -0
  72. package/test/tpl/partial/sent_list.html +7 -0
  73. package/test/tpl/partial/sent_list.js +1 -0
  74. package/test/tpl/partial/spam_list.es5.js +1 -0
  75. package/test/tpl/partial/spam_list.html +8 -0
  76. package/test/tpl/partial/spam_list.js +1 -0
  77. package/test/tpl/partial/trash_list.es5.js +1 -0
  78. package/test/tpl/partial/trash_list.html +7 -0
  79. package/test/tpl/partial/trash_list.js +1 -0
  80. package/test/tpl/partial/user.es5.js +1 -0
  81. package/test/tpl/partial/user.html +18 -0
  82. package/test/tpl/partial/user.js +1 -0
  83. package/tools/jsdoc.conf +47 -0
  84. package/tools/templates/docdash/publish.js +843 -0
  85. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  86. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  87. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  88. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  89. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  90. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  91. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  92. package/tools/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  93. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  94. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  95. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  96. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  97. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  98. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  99. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  100. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  101. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  102. package/tools/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  103. package/tools/templates/docdash/static/scripts/collapse.js +67 -0
  104. package/tools/templates/docdash/static/scripts/commonNav.js +28 -0
  105. package/tools/templates/docdash/static/scripts/linenumber.js +25 -0
  106. package/tools/templates/docdash/static/scripts/nav.js +12 -0
  107. package/tools/templates/docdash/static/scripts/polyfill.js +4 -0
  108. package/tools/templates/docdash/static/scripts/prettify/Apache-License-2.0.txt +202 -0
  109. package/tools/templates/docdash/static/scripts/prettify/lang-css.js +2 -0
  110. package/tools/templates/docdash/static/scripts/prettify/prettify.js +28 -0
  111. package/tools/templates/docdash/static/scripts/search.js +99 -0
  112. package/tools/templates/docdash/static/styles/jsdoc.css +803 -0
  113. package/tools/templates/docdash/static/styles/prettify.css +80 -0
  114. package/tools/templates/docdash/tmpl/augments.tmpl +10 -0
  115. package/tools/templates/docdash/tmpl/container.tmpl +203 -0
  116. package/tools/templates/docdash/tmpl/details.tmpl +152 -0
  117. package/tools/templates/docdash/tmpl/example.tmpl +2 -0
  118. package/tools/templates/docdash/tmpl/examples.tmpl +13 -0
  119. package/tools/templates/docdash/tmpl/exceptions.tmpl +32 -0
  120. package/tools/templates/docdash/tmpl/layout.tmpl +102 -0
  121. package/tools/templates/docdash/tmpl/mainpage.tmpl +15 -0
  122. package/tools/templates/docdash/tmpl/members.tmpl +38 -0
  123. package/tools/templates/docdash/tmpl/method.tmpl +132 -0
  124. package/tools/templates/docdash/tmpl/modifies.tmpl +14 -0
  125. package/tools/templates/docdash/tmpl/namespace.tmpl +133 -0
  126. package/tools/templates/docdash/tmpl/params.tmpl +132 -0
  127. package/tools/templates/docdash/tmpl/properties.tmpl +107 -0
  128. package/tools/templates/docdash/tmpl/returns.tmpl +19 -0
  129. package/tools/templates/docdash/tmpl/source.tmpl +8 -0
  130. package/tools/templates/docdash/tmpl/tutorial.tmpl +19 -0
  131. package/tools/templates/docdash/tmpl/type.tmpl +26 -0
  132. package/tools/templates/templates/docdash/publish.js +843 -0
  133. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  134. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  135. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  136. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  137. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  138. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  139. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  140. package/tools/templates/templates/docdash/static/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  141. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  142. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  143. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  144. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  145. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  146. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  147. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  148. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  149. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  150. package/tools/templates/templates/docdash/static/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  151. package/tools/templates/templates/docdash/static/scripts/collapse.js +67 -0
  152. package/tools/templates/templates/docdash/static/scripts/commonNav.js +28 -0
  153. package/tools/templates/templates/docdash/static/scripts/linenumber.js +25 -0
  154. package/tools/templates/templates/docdash/static/scripts/nav.js +12 -0
  155. package/tools/templates/templates/docdash/static/scripts/polyfill.js +4 -0
  156. package/tools/templates/templates/docdash/static/scripts/prettify/Apache-License-2.0.txt +202 -0
  157. package/tools/templates/templates/docdash/static/scripts/prettify/lang-css.js +2 -0
  158. package/tools/templates/templates/docdash/static/scripts/prettify/prettify.js +28 -0
  159. package/tools/templates/templates/docdash/static/scripts/search.js +99 -0
  160. package/tools/templates/templates/docdash/static/styles/jsdoc.css +803 -0
  161. package/tools/templates/templates/docdash/static/styles/prettify.css +80 -0
  162. package/tools/templates/templates/docdash/tmpl/augments.tmpl +10 -0
  163. package/tools/templates/templates/docdash/tmpl/container.tmpl +203 -0
  164. package/tools/templates/templates/docdash/tmpl/details.tmpl +152 -0
  165. package/tools/templates/templates/docdash/tmpl/example.tmpl +2 -0
  166. package/tools/templates/templates/docdash/tmpl/examples.tmpl +13 -0
  167. package/tools/templates/templates/docdash/tmpl/exceptions.tmpl +32 -0
  168. package/tools/templates/templates/docdash/tmpl/layout.tmpl +102 -0
  169. package/tools/templates/templates/docdash/tmpl/mainpage.tmpl +15 -0
  170. package/tools/templates/templates/docdash/tmpl/members.tmpl +38 -0
  171. package/tools/templates/templates/docdash/tmpl/method.tmpl +132 -0
  172. package/tools/templates/templates/docdash/tmpl/modifies.tmpl +14 -0
  173. package/tools/templates/templates/docdash/tmpl/namespace.tmpl +133 -0
  174. package/tools/templates/templates/docdash/tmpl/params.tmpl +132 -0
  175. package/tools/templates/templates/docdash/tmpl/properties.tmpl +107 -0
  176. package/tools/templates/templates/docdash/tmpl/returns.tmpl +19 -0
  177. package/tools/templates/templates/docdash/tmpl/source.tmpl +8 -0
  178. package/tools/templates/templates/docdash/tmpl/tutorial.tmpl +19 -0
  179. package/tools/templates/templates/docdash/tmpl/type.tmpl +26 -0
  180. package/tpl/partial/user.es5.js +1 -0
  181. package/tpl/partial/user.html +10 -0
  182. package/tpl/partial/user.js +1 -0
@@ -0,0 +1,923 @@
1
+
2
+ // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
3
+ const CONTACTS = 'contacts'
4
+ const MANIFEST = 'manifest'
5
+ const TOPICS = 'topics'
6
+
7
+ const CURRENT_PRIVATE_MESSAGE_VERSION = 1.2
8
+ // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
9
+ let g_search_table = {}
10
+ let g_when_table = {}
11
+ let g_all_keys = []
12
+
13
+ let g_prune_timeout = null
14
+
15
+ const TIMEOUT_THRESHHOLD = 4*60*60
16
+ const SIG_REQUIRED = false
17
+
18
+
19
+ var alert_error = (msg) => {
20
+ alert(msg)
21
+ console.log(new Error("stack"))
22
+ }
23
+
24
+ export function set_alert_error_handler(fn) {
25
+ if ( typeof fn === 'function' ) {
26
+ alert_error = fn
27
+ }
28
+ }
29
+
30
+
31
+ // got this from somewhere
32
+ function uuidv4() {
33
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
34
+ var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
35
+ return v.toString(16);
36
+ });
37
+ }
38
+
39
+
40
+ function gen_unique_id() {
41
+ let ky = uuidv4()
42
+ while ( g_all_keys.indexOf(ky) >= 0 ) ky = uuidv4()
43
+ return ky
44
+ }
45
+
46
+
47
+ // // https://www.copious.world/interplanetary-contact
48
+ var g_profile_port = '' // 6111
49
+ function correct_server(srvr) {
50
+ if ( srvr.indexOf(':5') > 0 ) {
51
+ srvr = srvr.replace('5111','6111') /// CHANGE ...
52
+ }
53
+ return srvr
54
+ }
55
+
56
+ var g_stem_prefix = 'interplanetary-contact/contact/' // by service...
57
+
58
+
59
+ // -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
60
+ // ASSETS
61
+
62
+
63
+ async function fetch_asset(topics_cid,identity,btype,asset) { // specifically from this user
64
+ //
65
+ let user_cid = identity.cid
66
+ //
67
+ let srver = location.host
68
+ srver = correct_server(srver)
69
+ //
70
+ let prot = location.protocol // prot for (prot)ocol
71
+
72
+ btype = btype ? true : false
73
+
74
+ let data_stem = `${g_stem_prefix}get-asset/${asset}`
75
+ let sp = '//'
76
+ let post_data = {
77
+ "btype" : btype,
78
+ "user_cid" : user_cid,
79
+ "cid" : topics_cid
80
+ }
81
+ let search_result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
82
+ if ( search_result ) {
83
+ if ( search_result.status === "OK" ) {
84
+ let data = search_result[asset];
85
+ if ( typeof data === 'string' ) {
86
+ let decryptor = await window.user_decryption(identity,asset) // user user cid to get the decryptor...
87
+ if ( decryptor !== undefined ) {
88
+ try {
89
+ data = await decryptor(data) // decryption
90
+ } catch (e) {
91
+ }
92
+ }
93
+ if ( data ) {
94
+ try {
95
+ let data_obj = JSON.parse(data)
96
+ return data_obj
97
+ } catch (e) {
98
+ return [false,data]
99
+ }
100
+ }
101
+ } else {
102
+ return data
103
+ }
104
+ }
105
+ } else {
106
+ return [false,search_result]
107
+ }
108
+ }
109
+
110
+
111
+ export async function fetch_contacts(contacts_cid,identity,btype) { // specifically from this user
112
+ return await fetch_asset(contacts_cid,identity,btype,CONTACTS)
113
+ }
114
+
115
+ export async function fetch_manifest(manifest_cid,identity,btype) { // specifically from this user
116
+ return await fetch_asset(manifest_cid,identity,btype,MANIFEST)
117
+ }
118
+
119
+ export async function fetch_topics(topics_cid,identity,btype) { // specifically from this user
120
+ return await fetch_asset(topics_cid,identity,btype,TOPICS)
121
+ }
122
+
123
+
124
+ // -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
125
+ // ASSETS
126
+
127
+
128
+ async function update_asset_to_ipfs(asset,identity,is_business,contents) {
129
+ let user_cid = identity.cid
130
+ let srver = location.host
131
+ srver = correct_server(srver)
132
+ //
133
+ if ( typeof contents !== 'string' ) {
134
+ contents = JSON.stringify(contents)
135
+ }
136
+ let encryptor = await window.user_encryption(identity,asset)
137
+ let encoded_contents = contents
138
+ if ( encryptor !== undefined ) { // encryption
139
+ encoded_contents = await encryptor(contents)
140
+ }
141
+ //
142
+ let prot = location.protocol // prot for (prot)ocol
143
+ let data_stem = `${g_stem_prefix}put-asset/${asset}`
144
+ let sp = '//'
145
+ let post_data = {
146
+ "cid" : user_cid,
147
+ "business" : is_business,
148
+ "contents" : encoded_contents
149
+ }
150
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
151
+ if ( result.status === "OK" ) {
152
+ return result.update_cid
153
+ }
154
+ return false
155
+ }
156
+
157
+
158
+ export async function update_contacts_to_ipfs(identity,is_business,contents) {
159
+ return await update_asset_to_ipfs(CONTACTS,identity,is_business,contents)
160
+ }
161
+
162
+ export async function update_manifest_to_ipfs(identity,is_business,contents) {
163
+ return await update_asset_to_ipfs(MANIFEST,identity,is_business,contents)
164
+ }
165
+
166
+ export async function update_topics_to_ipfs(identity,is_business,contents) {
167
+ return await update_asset_to_ipfs(TOPICS,identity,is_business,contents)
168
+ }
169
+
170
+ // // contact page
171
+ // -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
172
+
173
+ //
174
+ // fetch_contact_page
175
+ //
176
+ export async function fetch_contact_page(identity,business,asset,contact_cid) { // specifically from this user
177
+ let srver = location.host
178
+ srver = correct_server(srver)
179
+ //
180
+ let prot = location.protocol // prot for (prot)ocol
181
+ let data_stem = `${g_stem_prefix}get-contact-page/${asset}` // asset as parameter
182
+ let sp = '//'
183
+
184
+ let post_data = {
185
+ "cid" : contact_cid, //
186
+ "business" : business
187
+ }
188
+ let search_result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
189
+ if ( search_result ) {
190
+ let contact_form = search_result.contact;
191
+ let decryptor = window.user_decryption(identity,asset)
192
+ if ( decryptor !== undefined ) {
193
+ try {
194
+ contact_form = await decryptor(contact_form)
195
+ } catch (e) {
196
+ }
197
+ }
198
+ if ( contact_form ) {
199
+ if ( typeof contact_form === "string" ) {
200
+ let data_obj = JSON.parse(contact_form)
201
+ try {
202
+ return data_obj
203
+ } catch (e) {
204
+ }
205
+ } else {
206
+ return contact_form
207
+ }
208
+ }
209
+ }
210
+ return false
211
+ }
212
+
213
+ // //
214
+ // -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
215
+
216
+ let g_user_fields = ["name", "DOB", "place_of_origin", "cool_public_info", "business", "public_key", "signer_public_key", "biometric"]
217
+ // not checking for "cid" for most cases...
218
+ export async function add_profile(u_info) {
219
+ let user_info = Object.assign(u_info)
220
+ //
221
+ for ( let field of g_user_fields ) {
222
+ if ( user_info[field] === undefined ) {
223
+ if ( field === "public_key" ) {
224
+ let p_key = get_user_public_wrapper_key(`${user_info.name}-${user_info.DOB}`) // out of DB (index.html)
225
+ if ( p_key ) {
226
+ user_info.public_key = p_key
227
+ continue
228
+ }
229
+ }
230
+ if ( field === "signer_public_key" ) {
231
+ let p_key = get_user_public_signer_key(`${user_info.name}-${user_info.DOB}`) // out of DB (index.html)
232
+ if ( p_key ) {
233
+ user_info.signer_public_key = p_key
234
+ continue
235
+ }
236
+ }
237
+ alert_error("undefined field " + field)
238
+ return
239
+ }
240
+ }
241
+ if ( user_info.cid !== undefined ) { // remove reference to a cid when adding a new profile...
242
+ delete user_info.cid
243
+ }
244
+ let srver = location.host
245
+ srver = correct_server(srver)
246
+ //
247
+ let prot = location.protocol // prot for (prot)ocol
248
+ let data_stem = `${g_stem_prefix}add/profile`
249
+ let sp = '//'
250
+ let post_data = user_info
251
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
252
+ if ( result.status === "OK" ) {
253
+ let ipfs_identity = result.data
254
+ if ( typeof ipfs_identity.dir_data === 'string' ) {
255
+ ipfs_identity.dir_data = JSON.parse(ipfs_identity.dir_data)
256
+ }
257
+ // "id" : cid with key,
258
+ // "clear_id" : cid without key,
259
+ // "dir_data" : user directory structure
260
+ u_info.cid = ipfs_identity.id
261
+ await finalize_user_identity(u_info,ipfs_identity)
262
+ return true
263
+ }
264
+ return false
265
+ }
266
+
267
+
268
+ export async function fetch_contact_cid(someones_info,clear) { // a user,, not the owner of the manifest, most likely a recipients
269
+ let user_info = Object.assign({},someones_info)
270
+ for ( let field of g_user_fields ) {
271
+ if ( user_info[field] === undefined ) {
272
+ if ( (field === "public_key") && clear ) {
273
+ delete user_info.public_key
274
+ continue;
275
+ }
276
+ if ( (field === "signer_public_key") && clear ) {
277
+ delete user_info.signer_public_key
278
+ continue;
279
+ }
280
+ if ( (field === "biometric") && clear ) { // when wrapping a key use the recipients public wrapper key
281
+ // delete public_key key from messages that are introductions, etc. (this is used for the clear user directory id)
282
+ delete user_info.biometric
283
+ continue
284
+ }
285
+ alert_error("undefined field " + field)
286
+ return
287
+ }
288
+ }
289
+ let srver = location.host
290
+ srver = correct_server(srver)
291
+ //
292
+ let prot = location.protocol // prot for (prot)ocol
293
+ let data_stem = `${g_stem_prefix}get/user-cid`
294
+ let sp = '//'
295
+ let post_data = user_info
296
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
297
+ if ( result.status === "OK" ) {
298
+ let cid = result.cid
299
+ return cid
300
+ }
301
+ return false
302
+ }
303
+
304
+ export async function fetch_cid_json(jcid) {
305
+ if ( jcid === undefined ) return false
306
+ //
307
+ let data_stem = `${g_stem_prefix}get/json-cid/${jcid}`
308
+ let result = await fetchEndPoint(data_stem,g_profile_port)
309
+ if ( result.status === "OK" ) {
310
+ let json_str = result.json_str
311
+ if ( typeof json_str === "string" ) {
312
+ try {
313
+ displayable = JSON.parse(json_str)
314
+ return displayable
315
+ } catch (e) {}
316
+ } else {
317
+ return json_str
318
+ }
319
+ }
320
+ return false
321
+ }
322
+
323
+
324
+
325
+
326
+ export async function fetch_contact_info(cid) { // a user,, not the owner of the manifest, most likely a recipients
327
+ let srver = location.host
328
+ srver = correct_server(srver)
329
+ //
330
+ let prot = location.protocol // prot for (prot)ocol
331
+ let data_stem = `${g_stem_prefix}get/user-info`
332
+ let sp = '//'
333
+ let post_data = {
334
+ "cid" : cid
335
+ }
336
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
337
+ if ( result.status === "OK" ) {
338
+ let user_info = result.user_info
339
+ return user_info
340
+ }
341
+ return false
342
+ }
343
+
344
+
345
+
346
+
347
+ export async function get_dir(identity,clear) {
348
+ //
349
+ let user_info = identity.user_info
350
+ for ( let field of g_user_fields ) {
351
+ if ( user_info[field] === undefined ) {
352
+ if ( (field === "public_key") && !(clear) ) {
353
+ let p_key = get_user_public_wrapper_key(`${user_info.name}-${user_info.DOB}`)
354
+ if ( p_key ) {
355
+ user_info[field] = p_key
356
+ continue
357
+ }
358
+ }
359
+ if ( (field === "signer_public_key") && !(clear) ) {
360
+ //continue
361
+ let p_key = get_user_public_signer_key(`${user_info.name}-${user_info.DOB}`)
362
+ if ( p_key ) {
363
+ user_info[field] = p_key
364
+ continue
365
+ }
366
+ }
367
+ alert_error("undefined field " + field)
368
+ return
369
+ }
370
+ }
371
+ //
372
+ if ( clear ) {
373
+ delete user_info.public_key
374
+ }
375
+ //
376
+ let srver = location.host
377
+ srver = correct_server(srver)
378
+ //
379
+ let prot = location.protocol // prot for (prot)ocol
380
+ let data_stem = `${g_stem_prefix}dir`
381
+ let sp = '//'
382
+ let post_data = user_info
383
+ post_data.cid = identity.cid
384
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
385
+ if ( result.status === "OK" ) {
386
+ let dir_tree = result.data
387
+ try {
388
+ dir_tree = JSON.parse(dir_tree)
389
+ return dir_tree
390
+ } catch (e) {}
391
+ }
392
+ return false
393
+ }
394
+
395
+ // -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
396
+
397
+ let g_message_fields = ["name", "user_cid", "subject", "readers", "date", "when", "business", "public_key", "wrapped_key", "encoding","message"]
398
+ async function send_kind_of_message(m_path,recipient_info,identity,message,clear) {
399
+ //
400
+ let user_info = identity.user_info // from sender == user_info
401
+ // assume that user info has been properly formed and ready to act as recipient
402
+ //
403
+ // make sure that
404
+ let recipient = Object.assign({},recipient_info)
405
+ for ( let field of g_user_fields ) {
406
+ if ( (field === "public_key") && clear ) { // when wrapping a key use the recipients public wrapper key
407
+ // delete public_key key from messages that are introductions, etc. (this is used for the clear user directory id)
408
+ delete recipient_info.public_key
409
+ continue
410
+ }
411
+ if ( (field === "signer_public_key") && clear ) { // when wrapping a key use the recipients public wrapper key
412
+ // delete public_key key from messages that are introductions, etc. (this is used for the clear user directory id)
413
+ delete recipient_info.signer_public_key
414
+ continue
415
+ }
416
+ if ( (field === "biometric") && clear ) { // when wrapping a key use the recipients public wrapper key
417
+ // delete public_key key from messages that are introductions, etc. (this is used for the clear user directory id)
418
+ delete recipient_info.biometric
419
+ continue
420
+ }
421
+ if ( recipient[field] === undefined ) {
422
+ alert_error("undefined field " + field)
423
+ return
424
+ }
425
+ }
426
+
427
+ let sendable_message = Object.assign({},message)
428
+ //
429
+ let user_cid = identity.cid
430
+ sendable_message.user_cid = user_cid // cid of from (should have been set)
431
+ // the recipient will wrap key with this (so refresh his memory)
432
+ if ( clear ) {
433
+ sendable_message.public_key = user_info.public_key
434
+ sendable_message.signer_public_key = user_info.signer_public_key // send the signature key in the intro (just this once)
435
+ // the id of the clear directory ignores the key.
436
+ // the identity of established contact messages requires the public key (so it stays for not clear)
437
+ delete recipient.public_key // this has to do with the identiy and the directory where introductions go.
438
+ delete recipient.signer_public_key // and this. Clear identity does not use keys
439
+ } else {
440
+ //
441
+ if ( sendable_message.when === undefined ) sendable_message.when = Date.now()
442
+ if ( sendable_message.date === undefined ) sendable_message.date = (new Date(message.date)).toISOString()
443
+ if ( sendable_message.name === undefined ) sendable_message.name = user_info.name // from
444
+
445
+ // should have been set in the interface ... but can still catch this here.
446
+ sendable_message.public_key = user_info.public_key // basically says we know the recipient (we have talked)
447
+ sendable_message.nonce = message.nonce // for AES CBC...
448
+ //
449
+ // CAN'T PROCEED WITHOUT A KEY
450
+ //
451
+ let key_to_wrap = await window.gen_cipher_key() /// this will be an AES KEY, new each time.
452
+ if ( key_to_wrap === undefined || !(key_to_wrap) ) {
453
+ alert_error("could not get key ")
454
+ alert("no cipher key")
455
+ return
456
+ } else {
457
+ //
458
+ sendable_message.message = JSON.stringify(message) // STRINGIFY
459
+ //
460
+ let encryptor = await window.user_encryption(identity,"message") // encryptor may vary by user... assuming more than one in indexedDB
461
+ let encoded_contents = sendable_message.message
462
+ if ( encryptor !== undefined ) {
463
+ let aes_key = key_to_wrap // ENCRYPT
464
+ encoded_contents = await encryptor(encoded_contents,aes_key,sendable_message.nonce) // CBC starting with nonce...
465
+ }
466
+ sendable_message.message = encoded_contents // ENCODED
467
+ //
468
+ // WRAP the key just used with the public wrapper key of the recipient (got the key via introduction...)
469
+ sendable_message.wrapped_key = await window.key_wrapper(key_to_wrap,recipient.public_key)
470
+ // SIGN the wrapped key using the sender's private signer key (receiver should already have public signature...)
471
+ sendable_message.signature = await window.key_signer(sendable_message.wrapped_key,identity.signer_priv_key)
472
+ //
473
+ delete sendable_message.subject
474
+ delete sendable_message.readers
475
+ }
476
+
477
+ sendable_message.version = CURRENT_PRIVATE_MESSAGE_VERSION
478
+ }
479
+ //
480
+ let srver = location.host
481
+ srver = correct_server(srver)
482
+ //
483
+ let prot = location.protocol // prot for (prot)ocol
484
+ let data_stem = `${g_stem_prefix}${m_path}`
485
+ let sp = '//'
486
+ let post_data = {
487
+ "receiver" : recipient,
488
+ "message" : sendable_message
489
+ }
490
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
491
+ if ( result.status === "OK" ) {
492
+ let m_cid = result.message_cid
493
+ return m_cid
494
+ }
495
+ return false
496
+ }
497
+
498
+ /*
499
+ if ( !(introduction) && encrypting ) {
500
+ if ( encrypting ) {
501
+ message = {
502
+ "name" : active_identity.user_info.name,
503
+ "user_cid" : active_identity.cid
504
+ }
505
+ let [wrapped, aes_key] = get_wrapped_aes_key(public_key) // recipient's public wrapper key
506
+ message.wrapped_key = wrapped
507
+ message.ctext = get_encipherd_message(JSON.stringify(message_object),aes_key)
508
+ }
509
+ }
510
+ */
511
+
512
+
513
+ export async function send_message(recipient_info,identity,message) {
514
+ let m_path = 'send/message'
515
+ let result = await send_kind_of_message(m_path,recipient_info,identity,message,false)
516
+ return result
517
+ }
518
+
519
+
520
+ export async function send_introduction(recipient_info,identity,message) {
521
+ let m_path = 'send/introduction'
522
+ let result = await send_kind_of_message(m_path,recipient_info,identity,message,true)
523
+ return result
524
+ }
525
+
526
+
527
+ export async function send_topic(recipient_info,identity,message) {
528
+ let m_path = '/send/topic'
529
+ let result = await send_kind_of_message(m_path,recipient_info,identity,message,false)
530
+ return result
531
+ }
532
+
533
+
534
+ export async function send_topic_offer(recipient_info,identity,message) {
535
+ let m_path = '/send/topic_offer'
536
+ let result = await send_kind_of_message(m_path,recipient_info,identity,message,true)
537
+ return result
538
+ }
539
+
540
+ // -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
541
+
542
+ async function* message_decryptor(messages,identity) {
543
+ let priv_key = identity.priv_key
544
+ for ( let message of messages ) {
545
+ if ( message.version && (message.version > 1.0) ) {
546
+ let wrapped_key = message.wrapped_key
547
+ try {
548
+ let signature = message.signature
549
+ if ( signature || SIG_REQUIRED ) {
550
+ if ( !signature ) continue
551
+ let user_cid = message.user_cid
552
+ let contact = contact_from_cid(user_cid)
553
+ let signer_pub_key = contact.signer_public_key
554
+ //
555
+ let ok = await window.verifier(wrapped_key,signature,signer_pub_key)
556
+ if ( !(ok) ) continue
557
+ }
558
+ let clear_m = await window.decipher_message(message.message,wrapped_key,priv_key,message.nonce)
559
+ if ( clear_m !== false ) {
560
+ message.message = JSON.parse(clear_m)
561
+ } else {
562
+ continue
563
+ }
564
+ } catch (e) {}
565
+ }
566
+ yield message
567
+ }
568
+ }
569
+
570
+ async function clarify_message(messages,identity) {
571
+ let clear_messages = []
572
+ try {
573
+ for await (let message of message_decryptor(messages,identity) ) {
574
+ try {
575
+ let cmessage = false
576
+ if ( typeof message.message === "string" ) {
577
+ cmessage = JSON.parse(message.message)
578
+ } else {
579
+ cmessage = message.message
580
+ }
581
+ if ( message.f_cid ) {
582
+ cmessage.f_cid = message.f_cid
583
+ }
584
+ clear_messages.push(cmessage)
585
+ } catch (e) {
586
+ //clear_messages.push(message)
587
+ }
588
+ }
589
+ } catch (e) {
590
+ console.log('caught', e)
591
+ }
592
+ return(clear_messages)
593
+ }
594
+
595
+ // get_spool_files
596
+ // ---- identity - sender's information...
597
+ // ---- spool_select - the name of a spool, e.g. 'spool' 'deleted', 'read', 'events', etc.
598
+ // ---- clear -- WHICH PATHWAY -- use either the 'clear' cid path (no keys, no encryption) or use the key based message pathway, cid
599
+ // ---- offset -- offset into the dirctory list (paging)
600
+ // ---- count -- max per page
601
+ //
602
+ async function get_spool_files(identity,spool_select,clear,offset,count) {
603
+ //
604
+ let cid = identity.cid
605
+ if ( clear ) {
606
+ cid = identity.clear_cid
607
+ }
608
+ if ( cid === undefined ) return false
609
+ //
610
+ let srver = location.host
611
+ srver = correct_server(srver)
612
+ //
613
+ let prot = location.protocol // prot for (prot)ocol
614
+ let data_stem = `${g_stem_prefix}get-spool`
615
+ let sp = '//'
616
+ let post_data = {
617
+ 'cid' : cid,
618
+ 'spool' : spool_select, // false for introduction
619
+ 'business' : identity.user_info.business,
620
+ 'offset' : offset,
621
+ 'count' : count
622
+ }
623
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
624
+ if ( result.status === "OK" ) {
625
+ let messages = result.data
626
+ let cid_list = result.cid_list
627
+ try {
628
+ if ( Array.isArray(messages) ) {
629
+ messages = messages.map((msg,index) => {
630
+ if ( typeof msg === "string" ) {
631
+ try {
632
+ let obj = JSON.parse(msg)
633
+ if ( cid_list ) {
634
+ obj.f_cid = cid_list[index]
635
+ }
636
+ return obj
637
+ } catch(e) {
638
+ return msg
639
+ }
640
+ }
641
+ })
642
+ } else if ( typeof messages === 'string' ) {
643
+ messages = JSON.parse(messages)
644
+ }
645
+ if ( !clear ) {
646
+ messages = await clarify_message(messages,identity)
647
+ }
648
+ return messages
649
+ } catch (e) {}
650
+ }
651
+ return false
652
+ }
653
+
654
+
655
+ async function get_special_files(identity,op_category,offset,count) {
656
+ //
657
+ return await get_spool_files(identity,op_category,false,offset,count)
658
+ //
659
+ }
660
+
661
+
662
+ export async function get_message_files(identity,offset,count) {
663
+ // picks up both clear and encrypted messages...
664
+ //
665
+ // expected_messages -- decrypted messages from the key based identity
666
+ let expected_messages = await get_spool_files(identity,true,false,offset,count)
667
+ //
668
+ // solicitations -- message sent by those who don't have the receiver's public keys
669
+ let solicitations = await get_spool_files(identity,true,true,offset,count)
670
+ //
671
+ return [expected_messages,solicitations]
672
+ }
673
+
674
+ export async function get_topic_files(identity,offset,count) {
675
+ let expected_messages = await get_spool_files(identity,false,false,offset,count)
676
+ let solicitations = await get_spool_files(identity,false,true,offset,count)
677
+ return [expected_messages,solicitations]
678
+ }
679
+
680
+ export async function get_categorized_message_files(identity,op_category,offset,count) {
681
+ let expected_messages = await get_special_files(identity,op_category,offset,count)
682
+ return expected_messages
683
+ }
684
+
685
+
686
+ // -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
687
+ //
688
+ // PUBLIC TEMPLATES AVAILABLE FROM DESIGNERS....
689
+ //
690
+
691
+
692
+ export async function get_template_list(offset,count,category,btype) {
693
+ //
694
+ if ( category === undefined ) {
695
+ category = 'any'
696
+ }
697
+ //
698
+ let srver = location.host
699
+ srver = correct_server(srver)
700
+ //
701
+ let prot = location.protocol // prot for (prot)ocol
702
+ let data_stem = `${g_stem_prefix}template-list/${category}`
703
+ let sp = '//'
704
+ let post_data = {
705
+ 'category' : category,
706
+ 'business_types' : btype ? "business" : "profile",
707
+ 'start' : offset,
708
+ 'count' : count
709
+ }
710
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
711
+ if ( result.status === "OK" ) {
712
+ let t_list = result.templates
713
+ try {
714
+ t_list = JSON.parse(t_list)
715
+ return t_list
716
+ } catch (e) {}
717
+ }
718
+ return false
719
+ }
720
+
721
+
722
+
723
+ export async function get_contact_template(template_cid) {
724
+ //
725
+ let data_stem = `${g_stem_prefix}get/template-cid/${template_cid}`
726
+ let result = await fetchEndPoint(data_stem,g_profile_port)
727
+ if ( result.status === "OK" ) {
728
+ let contact_template = result.template
729
+ if ( typeof contact_template === "string" ) {
730
+ try {
731
+ contact_template = JSON.parse(contact_template)
732
+ return contact_template
733
+ } catch (e) {}
734
+ } else {
735
+ return contact_template
736
+ }
737
+ }
738
+ return false
739
+ }
740
+
741
+
742
+ export async function get_named_contact_template(template_name,biz) {
743
+ //
744
+ let biz_t = biz ? "business" : "profile"
745
+ let data_stem = `${g_stem_prefix}get/template-name/${biz_t}/${template_name}`
746
+ let result = await fetchEndPoint(data_stem,g_profile_port)
747
+ if ( result.status === "OK" ) {
748
+ let contact_template = result.data
749
+ try {
750
+ t_list = JSON.parse(contact_template)
751
+ return contact_template
752
+ } catch (e) {}
753
+ }
754
+ return false
755
+ }
756
+
757
+
758
+
759
+ export async function get_named_contact_template_cid(template_name,biz) {
760
+ let data_stem = `${g_stem_prefix}get/template-cid-from-name/${biz}/${template_name}`
761
+ let result = await fetchEndPoint(data_stem,g_profile_port)
762
+ if ( result.status === "OK" ) {
763
+ let cid = result.cid
764
+ return cid
765
+ }
766
+ return false
767
+ }
768
+
769
+
770
+ export async function put_contact_template(name,data) {
771
+ //
772
+ let srver = location.host
773
+ srver = correct_server(srver)
774
+ //
775
+ if ( typeof data !== 'string' ) {
776
+ data = JSON.stringify(data)
777
+ }
778
+ //
779
+ let prot = location.protocol // prot for (prot)ocol
780
+ let data_stem = `${g_stem_prefix}put/template`
781
+ let sp = '//'
782
+ let post_data = {
783
+ 'name' : name,
784
+ 'uri_encoded_json' : encodeURIComponent(data)
785
+ }
786
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
787
+ if ( result.status === "OK" ) {
788
+ let t_cid = result.template_cid
789
+ return t_cid
790
+ }
791
+ return false
792
+ }
793
+
794
+ // -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
795
+ //
796
+
797
+ export async function message_list_ops(user_cid,dst_cid,op,param,biz_t,message_list,src_cat) {
798
+ //
799
+ let srver = location.host
800
+ srver = correct_server(srver)
801
+ //
802
+ let prot = location.protocol // prot for (prot)ocol
803
+ let data_stem = `${g_stem_prefix}message-list-op/${op}`
804
+ let sp = '//'
805
+ let post_data = {
806
+ 'user_cid' : user_cid,
807
+ 'dst_cid' : dst_cid,
808
+ 'param' : param,
809
+ 'business' : biz_t,
810
+ 'message_list' : message_list.join(',')
811
+ }
812
+ if ( src_cat ) {
813
+ post_data.source_category = src_cat
814
+ }
815
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
816
+ if ( result.status === "OK" ) {
817
+ let t_cid = result.template_cid
818
+ return t_cid
819
+ }
820
+ return false
821
+ }
822
+
823
+
824
+ // -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
825
+ //
826
+
827
+ const CHUNK_SIZE = 1000000
828
+ // upload_data_file
829
+ export async function upload_data_file(name,blob64) {
830
+ //
831
+ let srver = location.host
832
+ srver = correct_server(srver)
833
+ //
834
+ let prot = location.protocol // prot for (prot)ocol
835
+ let data_stem = `${g_stem_prefix}put/blob`
836
+ let sp = '//'
837
+ let len = blob64.length
838
+ let post_data = {
839
+ "name" : name,
840
+ "tstamp" : Date.now(),
841
+ "offset" : 0,
842
+ "chunk" : "",
843
+ "end" : false
844
+ }
845
+ for ( let i = 0; i < len; i += CHUNK_SIZE ) {
846
+ let chunk = blob64.substr(i,CHUNK_SIZE)
847
+ post_data.chunk = chunk
848
+ post_data.offset = i
849
+ if ( (i + CHUNK_SIZE ) > len ) {
850
+ post_data.end = true
851
+ }
852
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
853
+ if ( result.status === "OK" ) {
854
+ if ( result.end_of_data ) {
855
+ let f_cid = result.cid
856
+ return f_cid
857
+ }
858
+ }
859
+ }
860
+
861
+ return false
862
+ //
863
+ }
864
+
865
+
866
+
867
+
868
+ export async function load_blob_as_url(blob_cid) {
869
+ let srver = location.host
870
+ srver = correct_server(srver)
871
+ //
872
+ let prot = location.protocol // prot for (prot)ocol
873
+ let data_stem = `${g_stem_prefix}get/blob`
874
+ let sp = '//'
875
+ let post_data = {
876
+ "cid" : blob_cid
877
+ }
878
+ let result = await postData(`${prot}${sp}${srver}/${data_stem}`, post_data)
879
+ if ( result.status === "OK" ) {
880
+ let data = result.data
881
+ return data
882
+ }
883
+ //
884
+ return false
885
+ }
886
+
887
+
888
+ // -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
889
+ //
890
+
891
+
892
+ // dont_store_html
893
+ export function dont_store_html(manifest_obj) {
894
+ //
895
+ let cc_forms = manifest_obj.custom_contact_forms
896
+ //
897
+ let cids = []
898
+ let cid_map = {}
899
+ if ( Array.isArray(cc_forms) ) {
900
+ for ( let entry of cc_forms ) {
901
+ delete entry.html;
902
+ let cid = entry.cid
903
+ if ( entry.preference === undefined ) {
904
+ entry.preference = 1.0
905
+ }
906
+ cids.push(entry.cid)
907
+ cid_map[cid] = entry
908
+ }
909
+ } else {
910
+ cid_map = cc_forms
911
+ for ( let cid in cc_forms ) {
912
+ let entry = cc_forms[cid]
913
+ delete entry.html;
914
+ entry.cid = cid
915
+ cids.push(cid)
916
+ }
917
+ }
918
+
919
+ manifest_obj.custom_contact_forms = cid_map
920
+ manifest_obj.sorted_cids = cids.sort((a,b) => {
921
+ return(cid_map[a].preference - cid_map[b].preference)
922
+ })
923
+ }