Skip to content
Snippets Groups Projects
  • Abhishek Ranjan's avatar
    a2cfef12
    chore(prot): Lite data url [AC-1577] · a2cfef12
    Abhishek Ranjan authored and Dennis B's avatar Dennis B committed
    Closes AC-1577. Lite data url
    
    ## Review Checklist
    
    **If any item is not complete, the merge request is not ready to be reviewed and must be marked `Draft:`.**
    
    - [ ] The merge request title is in the format `<change type>(<change scope>): <short description> [<task id>]`
      - For example, `feat(cli): add QR code generation [AC-123]`
      - For details, see [CONTRIBUTING.md](/CONTRIBUTING.md)
    - [ ] The description includes `Closes <jira task ID>` (or rarely `Updates <jira task ID>`)
    - [ ] The change is fully validated by tests that are run during CI
      - In most cases this means a test in "validate.sh"
      - In some cases, a Go test may be acceptable
      - Validation is not applicable to things like documentation updates
      - Purely UI/UX changes can be manually validated, such as changes to human-readable output
      - For all other changes, automated validation tests are an absolute requirement unless a maintainer specifically explains why they are not in a comment on this merge request
    - [ ] The change is marked with one of the validation labels
      - ~"validation::ci/cd" for changes validated by CI tests
      - ~"validation::manual" for changes validated by hand
      - ~"validation::deferred" for changes validated by a follow up merge request
      - ~"validation::not applicable" for changes where validation is not applicable
    
    ## Merge Checklist
    
    - [ ] CI is passing
    - [ ] Merge conflicts are resolved
    - [ ] All discussions are resolved
    
    Related to AC-1577
    a2cfef12
    History
    chore(prot): Lite data url [AC-1577]
    Abhishek Ranjan authored and Dennis B's avatar Dennis B committed
    Closes AC-1577. Lite data url
    
    ## Review Checklist
    
    **If any item is not complete, the merge request is not ready to be reviewed and must be marked `Draft:`.**
    
    - [ ] The merge request title is in the format `<change type>(<change scope>): <short description> [<task id>]`
      - For example, `feat(cli): add QR code generation [AC-123]`
      - For details, see [CONTRIBUTING.md](/CONTRIBUTING.md)
    - [ ] The description includes `Closes <jira task ID>` (or rarely `Updates <jira task ID>`)
    - [ ] The change is fully validated by tests that are run during CI
      - In most cases this means a test in "validate.sh"
      - In some cases, a Go test may be acceptable
      - Validation is not applicable to things like documentation updates
      - Purely UI/UX changes can be manually validated, such as changes to human-readable output
      - For all other changes, automated validation tests are an absolute requirement unless a maintainer specifically explains why they are not in a comment on this merge request
    - [ ] The change is marked with one of the validation labels
      - ~"validation::ci/cd" for changes validated by CI tests
      - ~"validation::manual" for changes validated by hand
      - ~"validation::deferred" for changes validated by a follow up merge request
      - ~"validation::not applicable" for changes where validation is not applicable
    
    ## Merge Checklist
    
    - [ ] CI is passing
    - [ ] Merge conflicts are resolved
    - [ ] All discussions are resolved
    
    Related to AC-1577
lite_data_account.go 832 B
package protocol

import (
	"crypto/sha256"
)

// ComputeLiteDataAccountId will compute the chain id from the first entry in the chain which defines
// the names as part of the external id's
// https://github.com/FactomProject/FactomDocs/blob/master/factomDataStructureDetails.md#chainid
func ComputeLiteDataAccountId(firstEntry DataEntry) []byte {
	var chainId [64]byte
	if firstEntry == nil {
		return chainId[:]
	}
	hash := sha256.New()

	n := len(firstEntry.GetData())
	for i := 1; i < n; i++ {
		idSum := sha256.Sum256(firstEntry.GetData()[i])
		hash.Write(idSum[:])
	}

	c := hash.Sum(nil)
	copy(chainId[:], c)
	return chainId[:32]
}

func (c *LiteDataAccount) AccountId() ([]byte, error) {
	head, err := ParseLiteDataAddress(c.Url)
	if err != nil {
		return nil, err
	}

	//reconstruct full lite chain id
	return head, nil
}