当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript tweetnacl.randomBytes函数代码示例

本文整理汇总了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);
 });
开发者ID:saltyrtc,项目名称:saltyrtc-client-js,代码行数:12,代码来源:client.spec.ts

示例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);
 });
开发者ID:saltyrtc,项目名称:saltyrtc-client-js,代码行数:12,代码来源:keystore.spec.ts

示例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);
 });
开发者ID:saltyrtc,项目名称:saltyrtc-client-js,代码行数:13,代码来源:integration.spec.ts

示例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);
        });

    });
开发者ID:saltyrtc,项目名称:saltyrtc-client-js,代码行数:46,代码来源:keystore.spec.ts


注:本文中的tweetnacl.randomBytes函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。