sender no longer needs file nonce
This commit is contained in:
parent
545da556d2
commit
4fb4041f13
|
@ -98,7 +98,7 @@ export default function(state, emitter) {
|
|||
await delay(200);
|
||||
try {
|
||||
metrics.startedUpload({ size, type });
|
||||
const ownedFile = await sender.upload(state.storage);
|
||||
const ownedFile = await sender.upload();
|
||||
state.storage.totalUploads += 1;
|
||||
metrics.completedUpload(ownedFile);
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ export default class FileSender extends Nanobus {
|
|||
});
|
||||
}
|
||||
|
||||
async upload(storage) {
|
||||
async upload() {
|
||||
const start = Date.now();
|
||||
const plaintext = await this.readFile();
|
||||
if (this.cancelled) {
|
||||
|
@ -81,8 +81,7 @@ export default class FileSender extends Nanobus {
|
|||
this.uploadRequest = null;
|
||||
this.progress = [1, 1];
|
||||
const secretKey = arrayToB64(this.keychain.rawSecret);
|
||||
const ownedFile = new OwnedFile(
|
||||
{
|
||||
const ownedFile = new OwnedFile({
|
||||
id: result.id,
|
||||
url: `${result.url}#${secretKey}`,
|
||||
name: this.file.name,
|
||||
|
@ -95,9 +94,7 @@ export default class FileSender extends Nanobus {
|
|||
secretKey: secretKey,
|
||||
nonce: this.keychain.nonce,
|
||||
ownerToken: result.ownerToken
|
||||
},
|
||||
storage
|
||||
);
|
||||
});
|
||||
return ownedFile;
|
||||
} catch (e) {
|
||||
this.msg = 'errorPageHeader';
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import Nanobus from 'nanobus';
|
||||
import { arrayToB64, b64ToArray } from './utils';
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
export default class Keychain extends Nanobus {
|
||||
export default class Keychain {
|
||||
constructor(secretKeyB64, nonce, ivB64) {
|
||||
super('Keychain');
|
||||
this._nonce = nonce || 'yRCdyQ1EMSA3mo4rqSkuNQ==';
|
||||
if (ivB64) {
|
||||
this.iv = b64ToArray(ivB64);
|
||||
|
@ -85,7 +83,6 @@ export default class Keychain extends Nanobus {
|
|||
set nonce(n) {
|
||||
if (n && n !== this._nonce) {
|
||||
this._nonce = n;
|
||||
this.emit('nonceChanged');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { arrayToB64 } from './utils';
|
|||
import { del, fileInfo, setParams, setPassword } from './api';
|
||||
|
||||
export default class OwnedFile {
|
||||
constructor(obj, storage) {
|
||||
constructor(obj) {
|
||||
this.id = obj.id;
|
||||
this.url = obj.url;
|
||||
this.name = obj.name;
|
||||
|
@ -16,8 +16,7 @@ export default class OwnedFile {
|
|||
this.ownerToken = obj.ownerToken;
|
||||
this.dlimit = obj.dlimit || 1;
|
||||
this.dtotal = obj.dtotal || 0;
|
||||
this.keychain = new Keychain(obj.secretKey, obj.nonce);
|
||||
this.keychain.on('nonceChanged', () => storage.writeFile(this));
|
||||
this.keychain = new Keychain(obj.secretKey);
|
||||
this._hasPassword = !!obj.hasPassword;
|
||||
}
|
||||
|
||||
|
@ -69,7 +68,6 @@ export default class OwnedFile {
|
|||
createdAt: this.createdAt,
|
||||
expiresAt: this.expiresAt,
|
||||
secretKey: arrayToB64(this.keychain.rawSecret),
|
||||
nonce: this.keychain.nonce,
|
||||
ownerToken: this.ownerToken,
|
||||
dlimit: this.dlimit,
|
||||
dtotal: this.dtotal,
|
||||
|
|
|
@ -43,7 +43,7 @@ class Storage {
|
|||
const k = this.engine.key(i);
|
||||
if (isFile(k)) {
|
||||
try {
|
||||
const f = new OwnedFile(JSON.parse(this.engine.getItem(k)), this);
|
||||
const f = new OwnedFile(JSON.parse(this.engine.getItem(k)));
|
||||
if (!f.id) {
|
||||
f.id = f.fileId;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue