sign(accountKey) {
    const block = this.params;
    if(!('type' in block) || !(block.type in TYPES))
      throw new FieldError('type');

    const fields = Object.keys(REQUIRED_FIELDS).reduce((out, param) => {
      if(REQUIRED_FIELDS[param].types.indexOf(TYPES[block.type]) !== -1) out.push(param);
      return out;
    }, []);

    const header = Uint8Array.from([
      0x52, // magic number
      0x43, // 43 for mainnet, 41 for testnet
      0x05, // version max
      0x05, // version using
      0x01, // version min
      0x03, // type (3 = publish)
      0x00, // extensions 16-bits
      TYPES[block.type], // extensions 16-bits ( block type )
    ]);

    const values = concat_uint8(fields.map(field => {
      if(!(field in block))
        throw new FieldError(field)

      const value = hex_uint8(valueForHash(field, block[field]));
      if(value.length !== REQUIRED_FIELDS[field].length)
        throw new FieldError(field);

      return value;
    }));

    const context = blake2bInit(32, null);
    blake2bUpdate(context, values);
    const hash = blake2bFinal(context);

    const signature = nacl.sign.detached(hash, hex_uint8(accountKey));
    const work = hex_uint8(block.work).reverse();

    return {
      msg: [ header, values, signature, work ].map(part => uint8_hex(part)).join(''),
      hash: uint8_hex(hash)
    };
  }
/*
    Compute hash, work, and signature for this block
    @param  accountKey String private key for account
    @return Object signed block
   */
Compute hash, work, and signature for this block
Compute hash work and signature for this block
sign(accountKey) {
    const block = this.params;
    if(!('type' in block) || !(block.type in TYPES))
      throw new FieldError('type');
    const fields = Object.keys(REQUIRED_FIELDS).reduce((out, param) => {
      if(REQUIRED_FIELDS[param].types.indexOf(TYPES[block.type]) !== -1) out.push(param);
      return out;
    }, []);
    const header = Uint8Array.from([
      0x52, 
      0x43, 
      0x05, 
      0x05, 
      0x01, 
      0x03, 
      0x00, 
      TYPES[block.type],  ( block type )
    ]);
    const values = concat_uint8(fields.map(field => {
      if(!(field in block))
        throw new FieldError(field)
      const value = hex_uint8(valueForHash(field, block[field]));
      if(value.length !== REQUIRED_FIELDS[field].length)
        throw new FieldError(field);
      return value;
    }));
    const context = blake2bInit(32, null);
    blake2bUpdate(context, values);
    const hash = blake2bFinal(context);
    const signature = nacl.sign.detached(hash, hex_uint8(accountKey));
    const work = hex_uint8(block.work).reverse();
    return {
      msg: [ header, values, signature, work ].map(part => uint8_hex(part)).join(''),
      hash: uint8_hex(hash)
    };
  }
sign ( accountKey ) { const block = this . params ; if ( ! ( 'type' in block ) || ! ( block . type in TYPES ) ) throw new FieldError ( 'type' ) ; const fields = Object . keys ( REQUIRED_FIELDS ) . reduce ( ( out , param ) => { if ( REQUIRED_FIELDS [ param ] . types . indexOf ( TYPES [ block . type ] ) !== - 1 ) out . push ( param ) ; return out ; } , [ ] ) ; const header = Uint8Array . from ( [ 0x52 , 0x43 , 0x05 , 0x05 , 0x01 , 0x03 , 0x00 , TYPES [ block . type ] , ] ) ; const values = concat_uint8 ( fields . map ( field => { if ( ! ( field in block ) ) throw new FieldError ( field ) const value = hex_uint8 ( valueForHash ( field , block [ field ] ) ) ; if ( value . length !== REQUIRED_FIELDS [ field ] . length ) throw new FieldError ( field ) ; return value ; } ) ) ; const context = blake2bInit ( 32 , null ) ; blake2bUpdate ( context , values ) ; const hash = blake2bFinal ( context ) ; const signature = nacl . sign . detached ( hash , hex_uint8 ( accountKey ) ) ; const work = hex_uint8 ( block . work ) . reverse ( ) ; return { msg : [ header , values , signature , work ] . map ( part => uint8_hex ( part ) ) . join ( '' ) , hash : uint8_hex ( hash ) } ; }
Compute hash, work, and signature for this block
Compute hash work and signature for this block
// magic number // 43 for mainnet, 41 for testnet // version max // version using // version min // type (3 = publish) // extensions 16-bits // extensions 16-bits ( block type )