braid-text 0.2.51 → 0.2.52
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/package.json +1 -1
- package/simpleton-client.js +9 -1
- package/test/test.html +0 -3
package/package.json
CHANGED
package/simpleton-client.js
CHANGED
|
@@ -65,7 +65,7 @@ function simpleton_client(url, {
|
|
|
65
65
|
signal: ac.signal
|
|
66
66
|
}).then(res => {
|
|
67
67
|
if (on_res) on_res(res)
|
|
68
|
-
res.subscribe(update => {
|
|
68
|
+
res.subscribe(async update => {
|
|
69
69
|
// Only accept the update if its parents == our current version
|
|
70
70
|
update.parents.sort()
|
|
71
71
|
if (current_version.length === update.parents.length
|
|
@@ -110,6 +110,14 @@ function simpleton_client(url, {
|
|
|
110
110
|
} else prev_state = apply_patches(prev_state, patches)
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
// if the server gave us a digest,
|
|
114
|
+
// go ahead and check it against our new state..
|
|
115
|
+
if (update.extra_headers &&
|
|
116
|
+
update.extra_headers["repr-digest"] &&
|
|
117
|
+
update.extra_headers["repr-digest"].startsWith('sha-256=') &&
|
|
118
|
+
update.extra_headers["repr-digest"] !== `sha-256=:${btoa(String.fromCharCode(...new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(prev_state)))))}:`)
|
|
119
|
+
throw new Error('repr-digest mismatch')
|
|
120
|
+
|
|
113
121
|
if (on_state) on_state(prev_state)
|
|
114
122
|
}
|
|
115
123
|
}, on_error)
|
package/test/test.html
CHANGED
|
@@ -157,9 +157,6 @@ runTest(
|
|
|
157
157
|
var parts = []
|
|
158
158
|
var p = new Promise(async (done, fail) => {
|
|
159
159
|
r2.subscribe(update => {
|
|
160
|
-
|
|
161
|
-
console.log(`update: ${JSON.stringify(update, null, 4)}`)
|
|
162
|
-
|
|
163
160
|
parts.push(update.extra_headers['repr-digest'])
|
|
164
161
|
if (parts.length > 1) done()
|
|
165
162
|
}, fail)
|