How to use @casual-simulation/crypto - 10 common examples

To help you get started, we’ve selected a few @casual-simulation/crypto 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 casual-simulation / aux / src / causal-trees / core2 / CausalRepoObject.spec.ts View on Github external
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,
                ])
            );
        });
    });
github casual-simulation / aux / src / causal-trees / core2 / CausalRepoObject.ts View on Github external
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]),
    };
}
github casual-simulation / aux / src / causal-trees / core2 / AtomIndex.ts View on Github external
export function hashAtoms(atoms: Atom[]): string {
    let hashes: string[] = [];
    for (let atom of atoms) {
        hashes.push(atom.hash);
    }
    hashes.sort();
    return getHash(hashes);
}
github casual-simulation / aux / src / causal-trees / core2 / Atom2.ts View on Github external
export function atomHash(
    id: AtomId,
    causeHash: string | null,
    value: T
): string {
    return getHash([
        causeHash || null,
        id.site,
        id.timestamp,
        id.priority,
        value,
    ]);
}
github casual-simulation / aux / src / aux-vm-node / managers / AuxChannelManagerImpl.spec.ts View on Github external
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());
    });
github casual-simulation / aux / src / causal-tree-server / ChannelManagerImpl.spec.ts View on Github external
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)],
github casual-simulation / aux / src / crypto-browser / BrowserSigningCryptoImpl.ts View on Github external
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();
    }
github casual-simulation / aux / src / crypto-browser / BrowserSigningCryptoImpl.ts View on Github external
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();
    }
github casual-simulation / aux / src / crypto-browser / BrowserSigningCryptoImpl.ts View on Github external
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);
    }
github casual-simulation / aux / src / crypto-browser / BrowserSigningCryptoImpl.ts View on Github external
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);
    }