signing.js
function parseSecretKey(secretKey) {
    const k = Buffer.from(secretKey, 'base64');

    if (k.length < 2 + 2 + 4 + 16 + 8 + 8 + 64) {
        throw new Error('Incorrect secret key length');
    }

    // Check signature algorithm.
    if (k[0] !== 69 /* 'E' */ || k[1] !== 100 /* 'd' */) {
        throw new Error('Unknown signature algorithm');
    }

    // Check KDF algorithm
    if (k[2] !== 66 /* 'B' */ || k[3] !== 75 /* 'K' */) {
        throw new Error('Unsupported KDF algorithm');
    }

    // Extract fields.
    const rounds = k.slice(4, 8).readUInt32BE(0);
    if (rounds !== 0) {
        throw new Error('Rounds must be 0; unlock key before passing to sign.')
    }

    const checksum = k.slice(24, 32);
    const num = Buffer.from(k.slice(32, 40));
    const key = Buffer.from(k.slice(40, 104));

    // Verify key checksum.
    if (!nacl.verify(checksum, nacl.hash(key).subarray(0, 8))) {
        throw new Error('Key checksum verification failure');
    }

    return {
        num,
        key
    };
}
function parseSecretKey(secretKey) {
    const k = Buffer.from(secretKey, 'base64');

    if (k.length < 2 + 2 + 4 + 16 + 8 + 8 + 64) {
        throw new Error('Incorrect secret key length');
    }

    // Check signature algorithm.
    if (k[0] !== 69 /* 'E' */ || k[1] !== 100 /* 'd' */) {
        throw new Error('Unknown signature algorithm');
    }

    // Check KDF algorithm
    if (k[2] !== 66 /* 'B' */ || k[3] !== 75 /* 'K' */) {
        throw new Error('Unsupported KDF algorithm');
    }

    // Extract fields.
    const rounds = k.slice(4, 8).readUInt32BE(0);
    if (rounds !== 0) {
        throw new Error('Rounds must be 0; unlock key before passing to sign.')
    }

    const checksum = k.slice(24, 32);
    const num = Buffer.from(k.slice(32, 40));
    const key = Buffer.from(k.slice(40, 104));

    // Verify key checksum.
    if (!nacl.verify(checksum, nacl.hash(key).subarray(0, 8))) {
        throw new Error('Key checksum verification failure');
    }

    return {
        num,
        key
    };
}
function parseSecretKey ( secretKey ) { const k = Buffer . from ( secretKey , 'base64' ) ; if ( k . length < 2 + 2 + 4 + 16 + 8 + 8 + 64 ) { throw new Error ( 'Incorrect secret key length' ) ; } // Check signature algorithm. if ( k [ 0 ] !== 69 /* 'E' */ || k [ 1 ] !== 100 /* 'd' */ ) { throw new Error ( 'Unknown signature algorithm' ) ; } // Check KDF algorithm if ( k [ 2 ] !== 66 /* 'B' */ || k [ 3 ] !== 75 /* 'K' */ ) { throw new Error ( 'Unsupported KDF algorithm' ) ; } // Extract fields. const rounds = k . slice ( 4 , 8 ) . readUInt32BE ( 0 ) ; if ( rounds !== 0 ) { throw new Error ( 'Rounds must be 0; unlock key before passing to sign.' ) } const checksum = k . slice ( 24 , 32 ) ; const num = Buffer . from ( k . slice ( 32 , 40 ) ) ; const key = Buffer . from ( k . slice ( 40 , 104 ) ) ; // Verify key checksum. if ( ! nacl . verify ( checksum , nacl . hash ( key ) . subarray ( 0 , 8 ) ) ) { throw new Error ( 'Key checksum verification failure' ) ; } return { num , key } ; }
Converts secretKey from base64-encoded representation
into a Uint8Array acceptable for nacl.sign.

Returns an object with key num and secret key.

{
num: Uint8Array
key: Uint8Array
}

Throws if key format is incorrect.

@param {string} secretKey
@returns {Object} object { num, key }
Converts secretKey from base64 - encoded representation into a Uint8Array acceptable for nacl . sign .