Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should support null for the previous commit', () => {
const commit = repoCommit(
'message',
new Date(2019, 9, 4, 9, 0, 0),
'hash',
null
);
expect(commit.hash).toEqual(
getHash([
'message',
new Date(2019, 9, 4, 9, 0, 0),
'hash',
null,
])
);
});
});
export function repoCommit(
message: string,
time: Date,
indexHash: string,
previousCommit: string
): CausalRepoCommit {
return {
type: 'commit',
message: message,
time: time,
index: indexHash,
previousCommit: previousCommit,
hash: getHash([message, time.toISOString(), indexHash, previousCommit]),
};
}
export function hashAtoms(atoms: Atom[]): string {
let hashes: string[] = [];
for (let atom of atoms) {
hashes.push(atom.hash);
}
hashes.sort();
return getHash(hashes);
}
export function atomHash(
id: AtomId,
causeHash: string | null,
value: T
): string {
return getHash([
causeHash || null,
id.site,
id.timestamp,
id.priority,
value,
]);
}
name: 'Server',
username: 'server',
token: 'token',
isGuest: false,
};
device = {
claims: {
[USERNAME_CLAIM]: 'server',
[DEVICE_ID_CLAIM]: 'serverDeviceId',
[SESSION_ID_CLAIM]: 'serverSessionId',
},
roles: [SERVER_ROLE],
};
store = new TestCausalTreeStore();
factory = auxCausalTreeFactory();
crypto = new TestCryptoImpl('ECDSA-SHA256-NISTP256');
crypto.valid = true;
manager = new AuxChannelManagerImpl(
user,
device,
store,
factory,
crypto,
[]
);
stored = new AuxCausalTree(storedTree(site(1)));
await stored.root();
store.put('test', stored.export());
});
beforeEach(async () => {
store = new TestCausalTreeStore();
factory = new CausalTreeFactory({
number: (stored, options) =>
new Tree(stored, new NumberReducer(), options),
broken: (stored, options) =>
new BrokenTree(stored, new NumberReducer(), options),
});
crypto = new TestCryptoImpl('ECDSA-SHA256-NISTP256');
crypto.valid = true;
manager = new ChannelManagerImpl(store, factory, crypto);
stored = new Tree(storedTree(site(1)), new NumberReducer());
await stored.create(new Op(), null);
store.put('test', stored.export());
stored = new Tree(storedTree(site(1)), new NumberReducer());
await stored.create(new Op(), null);
store.put('test02', stored.export());
store.put(
'broken',
storedTree(
site(1),
[site(1)],
async exportKey(key: SigningCryptoKey): Promise {
let buffer: ArrayBuffer;
if (key instanceof BrowserPublicCryptoKey) {
buffer = await crypto.subtle.exportKey('spki', key.publicKey);
return formatPublicPEMKey(buffer);
} else if (key instanceof BrowserPrivateCryptoKey) {
buffer = await crypto.subtle.exportKey('pkcs8', key.privateKey);
return formatPrivatePEMKey(buffer);
}
throw this._unknownKey();
}
async exportKey(key: SigningCryptoKey): Promise {
let buffer: ArrayBuffer;
if (key instanceof BrowserPublicCryptoKey) {
buffer = await crypto.subtle.exportKey('spki', key.publicKey);
return formatPublicPEMKey(buffer);
} else if (key instanceof BrowserPrivateCryptoKey) {
buffer = await crypto.subtle.exportKey('pkcs8', key.privateKey);
return formatPrivatePEMKey(buffer);
}
throw this._unknownKey();
}
async importPrivateKey(key: string): Promise {
const buffer = parsePrivatePEMKey(key);
const cryptoKey = await crypto.subtle.importKey(
'pkcs8',
buffer,
{
name: 'ECDSA',
namedCurve: BrowserSigningCryptoImpl.NAMED_CURVE,
},
true,
['sign']
);
return new BrowserPrivateCryptoKey(cryptoKey);
}
async importPublicKey(key: string): Promise {
const buffer = parsePublicPEMKey(key);
const cryptoKey = await crypto.subtle.importKey(
'spki',
buffer,
{
name: 'ECDSA',
namedCurve: BrowserSigningCryptoImpl.NAMED_CURVE,
},
true,
['verify']
);
return new BrowserPublicCryptoKey(cryptoKey);
}