本文整理匯總了TypeScript中tweetnacl.randomBytes函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript randomBytes函數的具體用法?TypeScript randomBytes怎麽用?TypeScript randomBytes使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了randomBytes函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('accepts hex strings as initiator pub key / auth token', () => {
const pubKey = nacl.randomBytes(32);
const authToken = nacl.randomBytes(32);
const salty = new SaltyRTCBuilder()
.connectTo('localhost')
.withKeyStore(new KeyStore())
.initiatorInfo(u8aToHex(pubKey), u8aToHex(authToken))
.usingTasks([new DummyTask()])
.asResponder();
expect(((salty as any).signaling as any).initiator.permanentSharedKey.remotePublicKeyBytes).toEqual(pubKey);
expect(((salty as any).signaling as any).authToken.keyBytes).toEqual(authToken);
});
示例2: it
it('can be created from a byte array', () => {
const nonceLength = nacl.box.nonceLength;
const nonce2 = nacl.randomBytes(nonceLength);
const data2 = nacl.randomBytes(5);
const array = new Uint8Array(nonceLength + 5);
array.set(nonce2);
array.set(data2, nonceLength);
const box2 = Box.fromUint8Array(array, nonceLength);
expect(box2.nonce).toEqual(nonce2);
expect(box2.data).toEqual(data2);
expect(box2.length).toEqual(nonceLength + 5);
});
示例3: it
spec = it('validate server auth success (responder)', (done: any) => {
console.info('===> TEST NAME:', spec.getFullName());
const responder = new SaltyRTCBuilder()
.connectTo(Config.SALTYRTC_HOST, Config.SALTYRTC_PORT)
.withKeyStore(new KeyStore())
.usingTasks([new DummyTask()])
.withServerKey(Config.SALTYRTC_SERVER_PUBLIC_KEY)
.initiatorInfo(nacl.randomBytes(32), nacl.randomBytes(32))
.asResponder();
expect(responder.state).toEqual('new');
responder.connect();
responder.once('state-change:peer-handshake', done);
});
示例4: describe
describe('Box', function() {
const nonce = nacl.randomBytes(24);
const data = nacl.randomBytes(7);
const box = new Box(nonce, data, 24);
it('correctly calculates the length', () => {
expect(box.length).toEqual(7 + 24);
});
it('correctly returns the data', () => {
expect(box.data).toEqual(data);
});
it('correctly returns the nonce', () => {
expect(box.nonce).toEqual(nonce);
});
it('can be created from a byte array', () => {
const nonceLength = nacl.box.nonceLength;
const nonce2 = nacl.randomBytes(nonceLength);
const data2 = nacl.randomBytes(5);
const array = new Uint8Array(nonceLength + 5);
array.set(nonce2);
array.set(data2, nonceLength);
const box2 = Box.fromUint8Array(array, nonceLength);
expect(box2.nonce).toEqual(nonce2);
expect(box2.data).toEqual(data2);
expect(box2.length).toEqual(nonceLength + 5);
});
it('validates the byte array length', () => {
const nonceLength = nacl.box.nonceLength;
const boxSameLength = () => Box.fromUint8Array(nacl.randomBytes(nonceLength), nonceLength);
const boxLessLength = () => Box.fromUint8Array(nacl.randomBytes(nonceLength - 2), nonceLength);
expect(boxSameLength).toThrow(new CryptoError('bad-message-length', 'Message is shorter than nonce'));
expect(boxLessLength).toThrow(new CryptoError('bad-message-length', 'Message is shorter than nonce'));
});
it('can be converted into a byte array', () => {
const array = box.toUint8Array();
expect(array.slice(0, nacl.secretbox.nonceLength)).toEqual(nonce);
expect(array.slice(nacl.secretbox.nonceLength)).toEqual(data);
});
});