You are viewing a single comment's thread from:

RE: How to encrypt a memo when transferring Steem

in #steem9 years ago (edited)

This is a random nonce with a time-based component. It returns a unique 64 bit unsigned number string.

    uniqueNonce() {
        if(unique_nonce_entropy === null) {
            const b = secureRandom.randomUint8Array(2)
            unique_nonce_entropy = parseInt(b[0] << 8 | b[1], 10)
        }
        let long = Long.fromNumber(Date.now())
        const entropy = ++unique_nonce_entropy % 0xFFFF
        long = long.shiftLeft(16).or(Long.fromNumber(entropy));
        return long.toString()
    }
    let unique_nonce_entropy = null

npm libraries used: long and secure-random