How to use the js-sha3.sha3_256.arrayBuffer function in js-sha3

To help you get started, we’ve selected a few js-sha3 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 nemtech / nem2-sdk-typescript-javascript / src / core / format / RawAddress.ts View on Github external
public static publicKeyToAddress = (publicKey: Uint8Array,
                                        networkType: NetworkType): Uint8Array => {
        // step 1: sha3 hash of the public key
        const signSchema = SHA3Hasher.resolveSignSchema(networkType);
        const publicKeyHash = signSchema === SignSchema.SHA3 ? sha3_256.arrayBuffer(publicKey) : keccak256.arrayBuffer(publicKey);

        // step 2: ripemd160 hash of (1)
        const ripemdHash = new RIPEMD160().update(new Buffer(publicKeyHash)).digest();

        // step 3: add network identifier byte in front of (2)
        const decodedAddress = new Uint8Array(RawAddress.constants.sizes.addressDecoded);
        decodedAddress[0] = networkType;
        RawArray.copy(decodedAddress, ripemdHash, RawAddress.constants.sizes.ripemd160, 1);

        // step 4: concatenate (3) and the checksum of (3)
        const hash = signSchema === SignSchema.SHA3 ?
            sha3_256.arrayBuffer(decodedAddress.subarray(0, RawAddress.constants.sizes.ripemd160 + 1)) :
            keccak256.arrayBuffer(decodedAddress.subarray(0, RawAddress.constants.sizes.ripemd160 + 1));

        RawArray.copy(decodedAddress, RawArray.uint8View(hash),
            RawAddress.constants.sizes.checksum, RawAddress.constants.sizes.ripemd160 + 1);
github nemtech / nem2-sdk-typescript-javascript / src / core / format / RawAddress.ts View on Github external
networkType: NetworkType): Uint8Array => {
        // step 1: sha3 hash of the public key
        const signSchema = SHA3Hasher.resolveSignSchema(networkType);
        const publicKeyHash = signSchema === SignSchema.SHA3 ? sha3_256.arrayBuffer(publicKey) : keccak256.arrayBuffer(publicKey);

        // step 2: ripemd160 hash of (1)
        const ripemdHash = new RIPEMD160().update(new Buffer(publicKeyHash)).digest();

        // step 3: add network identifier byte in front of (2)
        const decodedAddress = new Uint8Array(RawAddress.constants.sizes.addressDecoded);
        decodedAddress[0] = networkType;
        RawArray.copy(decodedAddress, ripemdHash, RawAddress.constants.sizes.ripemd160, 1);

        // step 4: concatenate (3) and the checksum of (3)
        const hash = signSchema === SignSchema.SHA3 ?
            sha3_256.arrayBuffer(decodedAddress.subarray(0, RawAddress.constants.sizes.ripemd160 + 1)) :
            keccak256.arrayBuffer(decodedAddress.subarray(0, RawAddress.constants.sizes.ripemd160 + 1));

        RawArray.copy(decodedAddress, RawArray.uint8View(hash),
            RawAddress.constants.sizes.checksum, RawAddress.constants.sizes.ripemd160 + 1);

        return decodedAddress;
    }
github nemtech / nem2-sdk-typescript-javascript / src / core / format / KeyGenerator.ts View on Github external
public static generateUInt64Key(input: string): UInt64 {
        if (input.length === 0) {
            throw Error(`Input must not be empty`);
        }
        const buf = sha3_256.arrayBuffer(input);
        const result = new Uint32Array(buf);
        return new UInt64([result[0], (result[1] | 0x80000000) >>> 0]);
    }
}