interledgerjs / five-bells-condition

JavaScript implementation of Crypto Conditions validation and fulfillment
https://github.com/rfcs/crypto-conditions
Other
31 stars 21 forks source link

Puzzled by Condition validation #67

Open sbellem opened 7 years ago

sbellem commented 7 years ago

The code for validating a condition is :

  validate () {
    // Get info for type ID, throws on error
    TypeRegistry.findByTypeId(this.getTypeId())

    // Bitmask can have at most 32 bits with current implementation
    if (this.getSubtypes() > Condition.MAX_SAFE_SUBTYPES) {
      throw new Error('Bitmask too large to be safely represented')
    }

    // Assert all requested features are supported by this implementation
    if (this.getSubtypes() & ~Condition.SUPPORTED_SUBTYPES) {
      throw new Error('Condition requested unsupported feature suites')
    }

    // Assert the requested fulfillment size is supported by this implementation
    if (this.getCost() > Condition.MAX_COST) {
      throw new Error('Condition requested too large of a max fulfillment size')
    }

    return true
  }

Given that subtypes is a set of strings, e.g.: Set {'preimage-sha-256', 'ed25519-sha-256'} what is the purpose of the checks > and & ~?