intantiate ephemeral channels with 34 hex characters
This commit is contained in:
@@ -76,9 +76,10 @@ define([
|
|||||||
return s.replace(/\/+/g, '/');
|
return s.replace(/\/+/g, '/');
|
||||||
};
|
};
|
||||||
|
|
||||||
Hash.createChannelId = function () {
|
Hash.ephemeralChannelLength = 34;
|
||||||
var id = uint8ArrayToHex(Crypto.Nacl.randomBytes(16));
|
Hash.createChannelId = function (ephemeral) {
|
||||||
if (id.length !== 32 || /[^a-f0-9]/.test(id)) {
|
var id = uint8ArrayToHex(Crypto.Nacl.randomBytes(ephemeral? 17: 16));
|
||||||
|
if ([32, 34].indexOf(id.length) === -1 || /[^a-f0-9]/.test(id)) {
|
||||||
throw new Error('channel ids must consist of 32 hex characters');
|
throw new Error('channel ids must consist of 32 hex characters');
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
|
|||||||
@@ -197,7 +197,10 @@ define([
|
|||||||
};
|
};
|
||||||
funcs.openCursorChannel = function (saveChanges) {
|
funcs.openCursorChannel = function (saveChanges) {
|
||||||
var md = JSON.parse(JSON.stringify(ctx.metadataMgr.getMetadata()));
|
var md = JSON.parse(JSON.stringify(ctx.metadataMgr.getMetadata()));
|
||||||
var channel = md.cursor || Hash.createChannelId();
|
var channel = md.cursor;
|
||||||
|
if (typeof(channel) !== 'string' || channel.length !== Hash.ephemeralChannelLength) {
|
||||||
|
channel = Hash.createChannelId(true); // true indicates that it's an ephemeral channel
|
||||||
|
}
|
||||||
if (!md.cursor) {
|
if (!md.cursor) {
|
||||||
md.cursor = channel;
|
md.cursor = channel;
|
||||||
ctx.metadataMgr.updateMetadata(md);
|
ctx.metadataMgr.updateMetadata(md);
|
||||||
|
|||||||
Reference in New Issue
Block a user