How to use stanza-shims - 10 common examples

To help you get started, we’ve selected a few stanza-shims examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github legastero / stanza / src / Utils.ts View on Github external
export function uuid() {
    const buf = randomBytes(16);

    // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
    buf[6] = (buf[6] & 0x0f) | 0x40;
    buf[8] = (buf[8] & 0x3f) | 0x80;

    let i = 0;
    return [
        bth[buf[i++]],
        bth[buf[i++]],
        bth[buf[i++]],
        bth[buf[i++]],
        '-',
        bth[buf[i++]],
        bth[buf[i++]],
        '-',
        bth[buf[i++]],
github legastero / stanza / src / transports / websocket.ts View on Github external
return this.disconnect();
                }
            }
            this.client.emit('stream:data', stanzaObj, name);
        });

        this.parser.on('error', (err: any) => {
            const streamError = {
                condition: StreamErrorCondition.InvalidXML
            };
            this.client.emit('stream:error', streamError, err);
            this.send(this.stanzas.export('error', streamError)!.toString());
            return this.disconnect();
        });

        this.conn = new WebSocket(opts.url, 'xmpp');
        this.conn.onerror = (e: any) => {
            if (e.preventDefault) {
                e.preventDefault();
            }
            console.error(e);
        };
        this.conn.onclose = (e: any) => {
            this.client.emit('disconnected', e);
        };
        this.conn.onopen = () => {
            this.sm.started = false;
            this.client.emit('connected');
            this.send(this.startHeader());
        };
        this.conn.onmessage = wsMsg => {
            const data = Buffer.from(wsMsg.data as string, 'utf8').toString();
github legastero / stanza / src / lib / sasl / index.ts View on Github external
export function H(text: Buffer, alg: string): Buffer {
    return Hashes.createHash(alg)
        .update(text)
        .digest();
}
github legastero / stanza / src / lib / sasl / index.ts View on Github external
.digest();
        const ha1 = Hashes.createHash('md5')
            .update(base)
            .update(':')
            .update(this.nonce!)
            .update(':')
            .update(cnonce);
        if (credentials.authzid) {
            ha1.update(':').update(credentials.authzid);
        }
        const dha1 = ha1.digest('hex');
        const ha2 = Hashes.createHash('md5')
            .update('AUTHENTICATE:')
            .update(uri);
        const dha2 = ha2.digest('hex');
        const digest = Hashes.createHash('md5')
            .update(dha1)
            .update(':')
            .update(this.nonce!)
            .update(':')
            .update(nc)
            .update(':')
            .update(cnonce)
            .update(':')
            .update(qop)
            .update(':')
            .update(dha2)
            .digest('hex');
        str += ',response=' + digest;
        if (this.charset === 'utf-8') {
            str += ',charset=utf-8';
        }
github legastero / stanza / src / jingle / FileTransferSession.ts View on Github external
constructor(opts = {}) {
        super();

        this.config = {
            chunkSize: 16384,
            hash: 'sha-1',
            ...opts
        };

        this.file = undefined;
        this.channel = undefined;
        this.hash = Hashes.createHash(this.config.hash);
    }
github legastero / stanza / src / helpers / LegacyEntityCapabilities.ts View on Github external
if (!identities || !features || !extensions) {
        return null;
    }

    for (const id of identities) {
        append(id);
    }
    for (const feature of features) {
        append(feature);
    }
    for (const form of extensions) {
        append(form);
    }

    return Hashes.createHash(hashName)
        .update(Buffer.concat(S))
        .digest('base64');
}
github legastero / stanza / src / lib / sasl / index.ts View on Github external
export function createClientNonce(length: number = 32): string {
    return Hashes.randomBytes(length).toString('hex');
}
github legastero / stanza / src / plugins / hostmeta.ts View on Github external
ssl: true,
        xrd: true,
        ...opts
    };

    const scheme = config.ssl ? 'https://' : 'http://';

    return promiseAny([
        fetch(`${scheme}${config.host}/.well-known/host-meta.json`).then(async res => {
            if (!res.ok) {
                throw new Error('could-not-fetch-json');
            }

            return res.json();
        }),
        fetch(`${scheme}${config.host}/.well-known/host-meta`).then(async res => {
            if (!res.ok) {
                throw new Error('could-not-fetch-xml');
            }

            const data = await res.text();
            const xml = JXT.parse(data);
            if (xml) {
                return registry.import(xml);
            }
        })
    ]);
}
github legastero / stanza / src / plugins / hostmeta.ts View on Github external
) {
    if (typeof opts === 'string') {
        opts = { host: opts };
    }

    const config = {
        json: true,
        ssl: true,
        xrd: true,
        ...opts
    };

    const scheme = config.ssl ? 'https://' : 'http://';

    return promiseAny([
        fetch(`${scheme}${config.host}/.well-known/host-meta.json`).then(async res => {
            if (!res.ok) {
                throw new Error('could-not-fetch-json');
            }

            return res.json();
        }),
        fetch(`${scheme}${config.host}/.well-known/host-meta`).then(async res => {
            if (!res.ok) {
                throw new Error('could-not-fetch-xml');
            }

            const data = await res.text();
            const xml = JXT.parse(data);
            if (xml) {
                return registry.import(xml);
            }
github legastero / stanza / src / transports / bosh.ts View on Github external
async function retryRequest(
    url: string,
    opts: RequestInit,
    timeout: number,
    allowedRetries: number = 5
): Promise {
    let attempt = 0;
    while (attempt <= allowedRetries) {
        try {
            const resp = await timeoutPromise(fetch(url, opts), timeout * 1000, () => {
                return new Error('Request timed out');
            });
            if (!resp.ok) {
                throw new Error('HTTP Status Error: ' + resp.status);
            }
            return resp.text();
        } catch (err) {
            attempt += 1;
            if (attempt > allowedRetries) {
                throw err;
            }
        }

        await sleep(Math.pow(attempt, 2) * 1000);
    }

stanza-shims

Runtime shims used by StanzaJS for node, browsers, and React Native

MIT
Latest version published 3 years ago

Package Health Score

42 / 100
Full package analysis