package emergencykit import ( "fmt" "strings" ) type DescriptorsData struct { FirstFingerprint string SecondFingerprint string } // Output descriptors shown in the PDF do not include legacy descriptors no longer in use. We leave // the decision of whether to scan them to the Recovery Tool. var descriptorFormats = []string{ "sh(wsh(multi(2, %s/1'/1'/0/*, %s/1'/1'/0/*)))", // V3 change "sh(wsh(multi(2, %s/1'/1'/1/*, %s/1'/1'/1/*)))", // V3 external "wsh(multi(2, %s/1'/1'/0/*, %s/1'/1'/0/*))", // V4 change "wsh(multi(2, %s/1'/1'/1/*, %s/1'/1'/1/*))", // V4 external } // GetDescriptors returns an array of raw output descriptors. func GetDescriptors(data *DescriptorsData) []string { var descriptors []string for _, descriptorFormat := range descriptorFormats { descriptor := fmt.Sprintf(descriptorFormat, data.FirstFingerprint, data.SecondFingerprint) checksum := calculateChecksum(descriptor) descriptors = append(descriptors, descriptor+"#"+checksum) } return descriptors } // GetDescriptorsHTML returns the HTML for the output descriptor list in the Emergency Kit. func GetDescriptorsHTML(data *DescriptorsData) string { descriptors := GetDescriptors(data) var itemsHTML []string for _, descriptor := range descriptors { descriptor, checksum := splitChecksum(descriptor) html := descriptor // Replace script type expressions (parenthesis in match prevent replacing the "sh" in "wsh") html = strings.ReplaceAll(html, "wsh(", renderScriptType("wsh")+"(") html = strings.ReplaceAll(html, "sh(", renderScriptType("sh")+"(") html = strings.ReplaceAll(html, "multi(", renderScriptType("multi")+"(") // Replace fingerprint expressions: html = strings.ReplaceAll(html, data.FirstFingerprint, renderFingerprint(data.FirstFingerprint)) html = strings.ReplaceAll(html, data.SecondFingerprint, renderFingerprint(data.SecondFingerprint)) // Add checksum and wrap everything: html += renderChecksum(checksum) html = renderItem(html) itemsHTML = append(itemsHTML, html) } return renderList(itemsHTML) } func renderList(itemsHTML []string) string { return fmt.Sprintf(`