├── larklogo.png ├── settings.gradle ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src └── main │ ├── deploy │ └── package │ │ ├── linux │ │ ├── lark.png │ │ ├── postinst │ │ └── lark.spec │ │ ├── macos │ │ ├── lark.icns │ │ ├── installer-background.png │ │ └── Lark.entitlements │ │ └── windows │ │ └── lark.ico │ ├── java │ ├── module-info.java │ └── com │ │ └── sparrowwallet │ │ └── larkapp │ │ ├── args │ │ ├── Command.java │ │ ├── AddrType.java │ │ ├── PromptPinCommand.java │ │ ├── TogglePassphraseCommand.java │ │ ├── EnumerateCommand.java │ │ ├── SendPinCommand.java │ │ ├── GetXpubCommand.java │ │ ├── SignMessageCommand.java │ │ ├── GetMasterXpubCommand.java │ │ ├── EnumeratedDevice.java │ │ ├── AbstractCommand.java │ │ ├── SignTxCommand.java │ │ ├── Args.java │ │ └── DisplayAddressCommand.java │ │ └── LarkCli.java │ └── resources │ └── logback.xml ├── runsparrow.bat ├── .gitmodules ├── runlark ├── .github └── workflows │ └── package.yaml ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE /larklogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparrowwallet/larkapp/HEAD/larklogo.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'larkapp' 2 | include 'drongo' 3 | include 'lark' -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .gradle 3 | *iml 4 | build 5 | /*.properties 6 | out 7 | *.log 8 | .DS_Store -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparrowwallet/larkapp/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/deploy/package/linux/lark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparrowwallet/larkapp/HEAD/src/main/deploy/package/linux/lark.png -------------------------------------------------------------------------------- /src/main/deploy/package/macos/lark.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparrowwallet/larkapp/HEAD/src/main/deploy/package/macos/lark.icns -------------------------------------------------------------------------------- /src/main/deploy/package/windows/lark.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparrowwallet/larkapp/HEAD/src/main/deploy/package/windows/lark.ico -------------------------------------------------------------------------------- /runsparrow.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set ARGS=%* 3 | 4 | if "%ARGS%" == "" ( 5 | gradlew.bat run 6 | ) else ( 7 | gradlew.bat run --args="%ARGS%" 8 | ) 9 | -------------------------------------------------------------------------------- /src/main/deploy/package/macos/installer-background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparrowwallet/larkapp/HEAD/src/main/deploy/package/macos/installer-background.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "drongo"] 2 | path = drongo 3 | url = ../../sparrowwallet/drongo.git 4 | branch = master 5 | [submodule "lark"] 6 | path = lark 7 | url = ../../sparrowwallet/lark.git 8 | branch = master 9 | -------------------------------------------------------------------------------- /src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | open module com.sparrowwallet.larkapp { 2 | requires com.sparrowwallet.lark; 3 | requires com.sparrowwallet.drongo; 4 | requires com.fasterxml.jackson.databind; 5 | requires org.jcommander; 6 | requires org.slf4j; 7 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/Command.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.sparrowwallet.lark.Lark; 5 | 6 | public interface Command { 7 | String getName(); 8 | void run(JCommander jCommander, Lark lark, Args args) throws Exception; 9 | } 10 | -------------------------------------------------------------------------------- /runlark: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | cd `dirname $0` 4 | 5 | args="" 6 | separator="" 7 | 8 | for arg in "$@"; do 9 | args+="${separator}\"$arg\"" 10 | separator=" " 11 | done 12 | 13 | args="${args%"${args##*[![:space:]]}"}" 14 | 15 | if [ -n "$args" ] 16 | then 17 | ./gradlew -q run --args="$args" 18 | else 19 | ./gradlew -q run 20 | fi 21 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/AddrType.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.sparrowwallet.drongo.protocol.ScriptType; 4 | 5 | public enum AddrType { 6 | legacy(ScriptType.P2PKH), wit(ScriptType.P2WPKH), sh_wit(ScriptType.P2SH_P2WPKH), tap(ScriptType.P2TR); 7 | 8 | private final ScriptType scriptType; 9 | 10 | AddrType(ScriptType scriptType) { 11 | this.scriptType = scriptType; 12 | } 13 | 14 | public ScriptType getScriptType() { 15 | return scriptType; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/deploy/package/macos/Lark.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.cs.allow-jit 6 | 7 | com.apple.security.cs.allow-unsigned-executable-memory 8 | 9 | com.apple.security.cs.disable-executable-page-protection 10 | 11 | com.apple.security.cs.disable-library-validation 12 | 13 | com.apple.security.cs.allow-dyld-environment-variables 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/PromptPinCommand.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.Parameters; 5 | import com.sparrowwallet.lark.Lark; 6 | 7 | @Parameters(commandDescription = "Have the device prompt for your PIN") 8 | public class PromptPinCommand extends AbstractCommand { 9 | @Override 10 | public String getName() { 11 | return "promptpin"; 12 | } 13 | 14 | @Override 15 | public void run(JCommander jCommander, Lark lark, Args args) throws Exception { 16 | super.run(jCommander, lark, args); 17 | 18 | boolean success; 19 | if(args.devicePath != null) { 20 | success = lark.promptPin(args.deviceType, args.devicePath); 21 | } else if(args.fingerprint != null) { 22 | success = lark.promptPin(args.fingerprint); 23 | } else { 24 | success = lark.promptPin(args.deviceType); 25 | } 26 | 27 | success(success); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/TogglePassphraseCommand.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.Parameters; 5 | import com.sparrowwallet.lark.Lark; 6 | 7 | @Parameters(commandDescription = "Toggle BIP39 passphrase") 8 | public class TogglePassphraseCommand extends AbstractCommand { 9 | @Override 10 | public String getName() { 11 | return "togglepassphrase"; 12 | } 13 | 14 | @Override 15 | public void run(JCommander jCommander, Lark lark, Args args) throws Exception { 16 | super.run(jCommander, lark, args); 17 | 18 | boolean success; 19 | if(args.devicePath != null) { 20 | success = lark.togglePassphrase(args.deviceType, args.devicePath); 21 | } else if(args.fingerprint != null) { 22 | success = lark.togglePassphrase(args.fingerprint); 23 | } else { 24 | success = lark.togglePassphrase(args.deviceType); 25 | } 26 | 27 | success(success); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/EnumerateCommand.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.Parameters; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import com.sparrowwallet.lark.HardwareClient; 7 | import com.sparrowwallet.lark.Lark; 8 | 9 | import java.util.List; 10 | 11 | @Parameters(commandDescription = "List all available devices") 12 | public class EnumerateCommand extends AbstractCommand { 13 | public static final String NAME = "enumerate"; 14 | 15 | @Override 16 | public String getName() { 17 | return NAME; 18 | } 19 | 20 | @Override 21 | public void run(JCommander jCommander, Lark lark, Args args) throws Exception { 22 | super.run(jCommander, lark, args); 23 | 24 | List clients = lark.enumerate(); 25 | ObjectMapper objectMapper = new ObjectMapper(); 26 | System.out.println(objectMapper.writeValueAsString(clients.stream().map(EnumeratedDevice::new).toList())); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/SendPinCommand.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.Parameter; 5 | import com.beust.jcommander.Parameters; 6 | import com.sparrowwallet.lark.Lark; 7 | 8 | import java.util.List; 9 | 10 | @Parameters(commandDescription = "Send the numeric positions for your PIN to the device") 11 | public class SendPinCommand extends AbstractCommand { 12 | @Parameter(description = "pin", required = true) 13 | public List pin; 14 | 15 | @Override 16 | public String getName() { 17 | return "sendpin"; 18 | } 19 | 20 | @Override 21 | public void run(JCommander jCommander, Lark lark, Args args) throws Exception { 22 | super.run(jCommander, lark, args); 23 | 24 | boolean success; 25 | if(args.devicePath != null) { 26 | success = lark.sendPin(args.deviceType, args.devicePath, pin.getFirst()); 27 | } else if(args.fingerprint != null) { 28 | success = lark.sendPin(args.fingerprint, pin.getFirst()); 29 | } else { 30 | success = lark.sendPin(args.deviceType, pin.getFirst()); 31 | } 32 | 33 | success(success); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/deploy/package/linux/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # postinst script for lark 3 | # 4 | # see: dh_installdeb(1) 5 | 6 | set -e 7 | 8 | # summary of how this script can be called: 9 | # * `configure' 10 | # * `abort-upgrade' 11 | # * `abort-remove' `in-favour' 12 | # 13 | # * `abort-remove' 14 | # * `abort-deconfigure' `in-favour' 15 | # `removing' 16 | # 17 | # for details, see https://www.debian.org/doc/debian-policy/ or 18 | # the debian-policy package 19 | 20 | package_type=deb 21 | 22 | 23 | case "$1" in 24 | configure) 25 | # Install the udev rules 26 | install -m 644 /opt/lark/lib/runtime/conf/udev/*.rules /etc/udev/rules.d 27 | 28 | # Reload the udev rules 29 | udevadm control --reload 30 | 31 | # Optionally trigger udev rules for currently connected devices 32 | udevadm trigger 33 | 34 | # Make sure the plugdev group exists 35 | groupadd -f plugdev 36 | 37 | # Make sure the current user is added to plugdev 38 | usermod -aG plugdev `whoami` 39 | 40 | ;; 41 | 42 | abort-upgrade|abort-remove|abort-deconfigure) 43 | ;; 44 | 45 | *) 46 | echo "postinst called with unknown argument \`$1'" >&2 47 | exit 1 48 | ;; 49 | esac 50 | 51 | exit 0 52 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | System.err 20 | 21 | %date %level %msg%n 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/GetXpubCommand.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.Parameter; 5 | import com.beust.jcommander.Parameters; 6 | import com.sparrowwallet.drongo.ExtendedKey; 7 | import com.sparrowwallet.drongo.KeyDerivation; 8 | import com.sparrowwallet.lark.Lark; 9 | 10 | import java.util.List; 11 | 12 | @Parameters(commandDescription = "Get an extended public key derived at a BIP 32 derivation path") 13 | public class GetXpubCommand extends AbstractCommand { 14 | @Parameter(description = "path", required = true) 15 | public List path; 16 | 17 | @Override 18 | public String getName() { 19 | return "getxpub"; 20 | } 21 | 22 | @Override 23 | public void run(JCommander jCommander, Lark lark, Args args) throws Exception { 24 | super.run(jCommander, lark, args); 25 | 26 | String xpubPath; 27 | try { 28 | xpubPath = KeyDerivation.writePath(KeyDerivation.parsePath(path.getFirst())); 29 | } catch(Exception e) { 30 | error("Invalid BIP32 path: " + path.getFirst()); 31 | return; 32 | } 33 | 34 | ExtendedKey xpub; 35 | if(args.devicePath != null) { 36 | xpub = lark.getPubKeyAtPath(args.deviceType, args.devicePath, xpubPath); 37 | } else if(args.fingerprint != null) { 38 | xpub = lark.getPubKeyAtPath(args.fingerprint, xpubPath); 39 | } else { 40 | xpub = lark.getPubKeyAtPath(args.deviceType, xpubPath); 41 | } 42 | 43 | value(new XpubValue(xpub.toString())); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/SignMessageCommand.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.Parameter; 5 | import com.beust.jcommander.Parameters; 6 | import com.sparrowwallet.drongo.KeyDerivation; 7 | import com.sparrowwallet.lark.Lark; 8 | 9 | import java.util.List; 10 | 11 | @Parameters(commandDescription = "Sign a message") 12 | public class SignMessageCommand extends AbstractCommand { 13 | @Parameter(description = "message path", arity = 2) 14 | public List params; 15 | 16 | @Override 17 | public String getName() { 18 | return "signmessage"; 19 | } 20 | 21 | @Override 22 | public void run(JCommander jCommander, Lark lark, Args args) throws Exception { 23 | super.run(jCommander, lark, args); 24 | 25 | String message = params.getFirst(); 26 | String path = params.getLast(); 27 | try { 28 | path = KeyDerivation.writePath(KeyDerivation.parsePath(path)); 29 | } catch(Exception e) { 30 | error("Invalid BIP32 path: " + path); 31 | return; 32 | } 33 | 34 | String signature; 35 | if(args.devicePath != null) { 36 | signature = lark.signMessage(args.deviceType, args.devicePath, message, path); 37 | } else if(args.fingerprint != null) { 38 | signature = lark.signMessage(args.fingerprint, message, path); 39 | } else { 40 | signature = lark.signMessage(args.deviceType, message, path); 41 | } 42 | 43 | value(new SignatureValue(signature)); 44 | } 45 | 46 | private record SignatureValue(String signature) {} 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/GetMasterXpubCommand.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.Parameter; 5 | import com.beust.jcommander.Parameters; 6 | import com.sparrowwallet.drongo.ExtendedKey; 7 | import com.sparrowwallet.drongo.KeyDerivation; 8 | import com.sparrowwallet.lark.Lark; 9 | 10 | @Parameters(commandDescription = "Get the extended public key for BIP 44 standard derivation paths. Convenience function to get xpubs given the address type, account, and chain type.") 11 | public class GetMasterXpubCommand extends AbstractCommand { 12 | @Parameter(names = { "--addr-type" }, description = "Get the master xpub used to derive addresses for this address type") 13 | public AddrType addrType = AddrType.wit; 14 | 15 | @Parameter(names = { "--account" }, description = "The account number") 16 | public int account = 0; 17 | 18 | @Override 19 | public String getName() { 20 | return "getmasterxpub"; 21 | } 22 | 23 | @Override 24 | public void run(JCommander jCommander, Lark lark, Args args) throws Exception { 25 | super.run(jCommander, lark, args); 26 | 27 | String path = KeyDerivation.writePath(addrType.getScriptType().getDefaultDerivation(account)); 28 | 29 | ExtendedKey xpub; 30 | if(args.devicePath != null) { 31 | xpub = lark.getPubKeyAtPath(args.deviceType, args.devicePath, path); 32 | } else if(args.fingerprint != null) { 33 | xpub = lark.getPubKeyAtPath(args.fingerprint, path); 34 | } else { 35 | xpub = lark.getPubKeyAtPath(args.deviceType, path); 36 | } 37 | 38 | value(new XpubValue(xpub.toString())); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/EnumeratedDevice.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import com.fasterxml.jackson.annotation.JsonPropertyOrder; 6 | import com.sparrowwallet.lark.HardwareClient; 7 | 8 | import java.util.Locale; 9 | 10 | @JsonPropertyOrder({"type", "path", "model", "label", "fingerprint", "needs_pin_sent", "needs_passphrase_sent", "error"}) 11 | class EnumeratedDevice { 12 | private final HardwareClient hardwareClient; 13 | 14 | public EnumeratedDevice(HardwareClient hardwareClient) { 15 | this.hardwareClient = hardwareClient; 16 | } 17 | 18 | public String getType() { 19 | return hardwareClient.getType().toLowerCase(Locale.ROOT); 20 | } 21 | 22 | public String getModel() { 23 | return hardwareClient.getProductModel().toLowerCase(Locale.ROOT); 24 | } 25 | 26 | public String getLabel() { 27 | return hardwareClient.getLabel(); 28 | } 29 | 30 | public String getPath() { 31 | return hardwareClient.getPath(); 32 | } 33 | 34 | @JsonInclude(JsonInclude.Include.NON_NULL) 35 | public String getFingerprint() { 36 | return hardwareClient.fingerprint(); 37 | } 38 | 39 | @JsonInclude(JsonInclude.Include.NON_NULL) 40 | @JsonProperty("needs_pin_sent") 41 | public Boolean isNeedsPinSent() { 42 | return hardwareClient.needsPinSent(); 43 | } 44 | 45 | @JsonInclude(JsonInclude.Include.NON_NULL) 46 | @JsonProperty("needs_passphrase_sent") 47 | public Boolean isNeedsPassphraseSent() { 48 | return hardwareClient.needsPassphraseSent(); 49 | } 50 | 51 | @JsonInclude(JsonInclude.Include.NON_NULL) 52 | public String getError() { 53 | return hardwareClient.error(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /.github/workflows/package.yaml: -------------------------------------------------------------------------------- 1 | name: Package 2 | 3 | on: workflow_dispatch 4 | 5 | permissions: 6 | contents: read 7 | 8 | jobs: 9 | build: 10 | runs-on: ${{ matrix.os }} 11 | strategy: 12 | matrix: 13 | os: [windows-2022, ubuntu-20.04, ubuntu-22.04-arm, macos-15-intel, macos-14] 14 | steps: 15 | - uses: actions/checkout@v4 16 | with: 17 | submodules: true 18 | - name: Set up JDK 22.0.2 19 | uses: actions/setup-java@v4 20 | with: 21 | distribution: 'temurin' 22 | java-version: '22.0.2' 23 | - name: Show Build Versions 24 | run: ./gradlew -v 25 | - name: Build with Gradle 26 | run: ./gradlew jpackage 27 | - name: Codesign, package and notarize macOS distribution 28 | if: ${{ runner.os == 'macOS' }} 29 | uses: sparrowwallet/github-actions/codesign-macos@v1 30 | with: 31 | app-name: Lark 32 | certificate: ${{ secrets.MACOS_CERTIFICATE }} 33 | certificate-password: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }} 34 | apple-id: ${{ secrets.MACOS_NOTARIZATION_APPLE_ID }} 35 | team-id: ${{ secrets.MACOS_NOTARIZATION_TEAM_ID }} 36 | notarization-password: ${{ secrets.MACOS_NOTARIZATION_PASSWORD }} 37 | - name: Package Windows zip distribution 38 | if: ${{ runner.os == 'Windows' || runner.os == 'macOS' }} 39 | run: ./gradlew packageZipDistribution 40 | - name: Package Linux tar distribution 41 | if: ${{ runner.os == 'Linux' }} 42 | run: ./gradlew packageTarDistribution 43 | - name: Upload Artifacts 44 | uses: actions/upload-artifact@v4 45 | with: 46 | name: Lark Build - ${{ runner.os }} ${{ runner.arch }} 47 | path: | 48 | build/jpackage/* 49 | !build/jpackage/Lark/ 50 | !build/jpackage/lark/ 51 | !build/jpackage/Lark.app/ 52 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/AbstractCommand.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.Parameter; 5 | import com.sparrowwallet.drongo.OutputDescriptor; 6 | import com.sparrowwallet.drongo.Utils; 7 | import com.sparrowwallet.lark.Lark; 8 | import com.sparrowwallet.larkapp.LarkCli; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | import java.util.stream.Collectors; 13 | 14 | public abstract class AbstractCommand implements Command { 15 | @Parameter(names = { "--help", "-h" }, description = "Show this help message and exit", help = true) 16 | public boolean help; 17 | 18 | @Override 19 | public void run(JCommander jCommander, Lark lark, Args args) throws Exception { 20 | if(help) { 21 | jCommander.usage(getName()); 22 | System.exit(0); 23 | } 24 | if(!EnumerateCommand.NAME.equals(getName())) { 25 | if(args.deviceType == null && args.fingerprint == null) { 26 | error("You must specify a device type or fingerprint for all commands except enumerate"); 27 | } 28 | } 29 | } 30 | 31 | protected Map getNewRegistrations(Lark lark, Map existingRegistrations) { 32 | Map newRegistrations = new HashMap<>(lark.getWalletRegistrations()); 33 | newRegistrations.keySet().removeAll(existingRegistrations.keySet()); 34 | return newRegistrations.entrySet().stream() 35 | .collect(Collectors.toMap(entry -> entry.getKey().toString(), entry -> new WalletRegistration(lark.getWalletName(entry.getKey()), Utils.bytesToHex(entry.getValue())))); 36 | } 37 | 38 | protected void success(boolean success) { 39 | LarkCli.showSuccess(success); 40 | } 41 | 42 | protected void value(Object value) { 43 | LarkCli.showValue(value); 44 | } 45 | 46 | protected void error(String errorMessage) { 47 | LarkCli.showErrorAndExit(errorMessage); 48 | } 49 | 50 | protected record XpubValue(String xpub) {} 51 | 52 | protected record WalletRegistration(String name, String registration) {} 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/SignTxCommand.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.Parameter; 5 | import com.beust.jcommander.Parameters; 6 | import com.fasterxml.jackson.annotation.JsonInclude; 7 | import com.sparrowwallet.drongo.OutputDescriptor; 8 | import com.sparrowwallet.drongo.psbt.PSBT; 9 | import com.sparrowwallet.lark.Lark; 10 | 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | @Parameters(commandDescription = "Sign a PSBT") 16 | public class SignTxCommand extends AbstractCommand{ 17 | @Parameter(description = "psbt", required = true, arity = 1) 18 | public List psbt; 19 | 20 | @Override 21 | public String getName() { 22 | return "signtx"; 23 | } 24 | 25 | @Override 26 | public void run(JCommander jCommander, Lark lark, Args args) throws Exception { 27 | super.run(jCommander, lark, args); 28 | 29 | String strUnsignedPsbt = psbt.getFirst(); 30 | PSBT unsignedPsbt; 31 | try { 32 | unsignedPsbt = PSBT.fromString(strUnsignedPsbt); 33 | } catch(Exception e) { 34 | error(e.getMessage()); 35 | return; 36 | } 37 | 38 | Map existingRegistrations = new HashMap<>(lark.getWalletRegistrations()); 39 | PSBT signedPsbt; 40 | if(args.devicePath != null) { 41 | signedPsbt = lark.signTransaction(args.deviceType, args.devicePath, unsignedPsbt); 42 | } else if(args.fingerprint != null) { 43 | signedPsbt = lark.signTransaction(args.fingerprint, unsignedPsbt); 44 | } else { 45 | signedPsbt = lark.signTransaction(args.deviceType, unsignedPsbt); 46 | } 47 | 48 | String strSignedPSBT = signedPsbt.toBase64String(); 49 | Map newRegistrations = getNewRegistrations(lark, existingRegistrations); 50 | value(new PSBTValue(strSignedPSBT, !strSignedPSBT.equals(strUnsignedPsbt), newRegistrations)); 51 | } 52 | 53 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 54 | private record PSBTValue(String psbt, boolean signed, Map registrations) {} 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/Args.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.Parameter; 4 | import com.sparrowwallet.drongo.Network; 5 | import com.sparrowwallet.lark.Chain; 6 | import org.slf4j.event.Level; 7 | 8 | public class Args { 9 | @Parameter(names = { "--device-path", "-d" }, description = "Specify the device path of the device to connect to", defaultValueDescription = "None") 10 | public String devicePath; 11 | 12 | @Parameter(names = { "--device-type", "-t" }, description = "Specify the type of device that will be connected. If `--device-path` not given, the first device of this type enumerated is used.", defaultValueDescription = "None") 13 | public String deviceType; 14 | 15 | @Parameter(names = { "--passphrase", "--password", "-p" }, description = "Device passphrase if it has one", defaultValueDescription = "None", password = true) 16 | public String passphrase; 17 | 18 | @Parameter(names = { "--network", "-n" }, description = "Select network to work with") 19 | public Network network; 20 | 21 | @Parameter(names = { "--chain" }, description = "Legacy alternative to select network to work with. If `--network` is provided it takes priority") 22 | public Chain chain; 23 | 24 | @Parameter(names = { "--level", "-l" }, description = "Set log level") 25 | public Level level; 26 | 27 | @Parameter(names = { "--debug" }, description = "Set log level to debug. If `--level` is provided it takes priority") 28 | public boolean debug; 29 | 30 | @Parameter(names = { "--stdin" }, description = "Enter commands and arguments via stdin") 31 | public boolean stdin; 32 | 33 | @Parameter(names = { "--fingerprint", "-f" }, description = "Specify the device to connect to using the first 4 bytes of the hash160 of the master public key. It will connect to the first device that matches this fingerprint.") 34 | public byte[] fingerprint; 35 | 36 | @Parameter(names = { "--version" }, description = "Show program's version number and exit") 37 | public boolean version; 38 | 39 | @Parameter(names = { "--emulators" }, description = "Enable enumeration and detection of device emulators") 40 | public boolean emulators; 41 | 42 | @Parameter(names = { "--wallet-desc", "-w" }, description = "Output descriptor of the wallet (used to set the wallet name)") 43 | public String walletDescriptor; 44 | 45 | @Parameter(names = { "--wallet-name" }, description = "Name of the wallet. `--wallet-desc` must also be provided") 46 | public String walletName; 47 | 48 | @Parameter(names = { "--wallet-registration" }, description = "Registration identifier of the wallet provided in hex. `--wallet-desc` and `--wallet-name` must also be provided. For Ledger, this is the wallet policy HMAC") 49 | public String walletRegistration; 50 | 51 | @Parameter(names = { "--help", "-h" }, description = "Show this help message and exit", help = true) 52 | public boolean help; 53 | } 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Lark logo](https://github.com/sparrowwallet/larkapp/raw/refs/heads/master/larklogo.png) 2 | 3 | # Lark App 4 | 5 | The Lark application is a command line app for interacting with USB hardware wallets in Bitcoin related functions. 6 | It uses the Lark Java library at https://github.com/sparrowwallet/lark, which in turn is a port of the Python library [HWI](https://github.com/bitcoin-core/HWI). 7 | The Lark command line application is designed to be a drop-in replacement for HWI, with a subset of commands implemented. 8 | Documentation on the commands is available by running it with `--help`. 9 | 10 | ## Running 11 | 12 | Depending on your operating system, once extracted/installed, Lark can be run from the command line as follows: 13 | 14 | #### Linux 15 | ```shell 16 | > lark/bin/lark 17 | ``` 18 | 19 | Note that on Linux, udev rules [may need to be installed](https://github.com/sparrowwallet/lark/blob/master/src/main/resources/udev/README.md) if you are not using the .deb/.rpm installation package. 20 | 21 | #### macOS 22 | ```shell 23 | > Lark.app/Contents/MacOS/Lark 24 | ``` 25 | 26 | #### Windows 27 | ```shell 28 | > lark/lark.exe 29 | ``` 30 | 31 | ### Example usage 32 | 33 | Show usage: 34 | 35 | ```shell 36 | lark --help 37 | ``` 38 | 39 | Enumerate all connected hardware wallets 40 | 41 | ```shell 42 | lark enumerate 43 | ``` 44 | 45 | Get Native Segwit xpub 46 | 47 | ```shell 48 | lark --device-type trezor getxpub "m/84'/0'/0'" 49 | ``` 50 | 51 | Sign a testnet transaction 52 | 53 | ```shell 54 | lark --chain test --device-type coldcard signtx "cHNid..." 55 | ``` 56 | 57 | Sign a multisig transaction, supplying a previous wallet registration 58 | 59 | ```shell 60 | lark --device-type ledger --wallet-desc "wsh(sortedmulti(2,[2811576b/48h/0h/0h/2h]xpub...,[6533280b/48h/0h/0h/2h]xpub...))" --wallet-name "2 of 2 Multisig" --wallet-registration "c0ee51bae9b3e5ee5a5e01dbcd336cd5c5f8a5b760d1c68f6a2a0b91c2580406" signtx "cHNid..." 61 | ``` 62 | 63 | ### Running from source 64 | 65 | If you prefer to run Lark directly from source, it can be launched from within the project directory with 66 | 67 | `./runlark` 68 | 69 | Java 22 or higher must be installed. 70 | 71 | 72 | ## Building 73 | 74 | To clone this project, use 75 | 76 | `git clone --recursive git@github.com:sparrowwallet/larkapp.git` 77 | 78 | or for those without SSH credentials: 79 | 80 | `git clone --recursive https://github.com/sparrowwallet/larkapp.git` 81 | 82 | In order to build, Lark requires Java 22 or higher to be installed. 83 | The release binaries are built with [Eclipse Temurin 22.0.2+9](https://github.com/adoptium/temurin22-binaries/releases/tag/jdk-22.0.2%2B9). 84 | 85 | Other packages may also be necessary to build depending on the platform. On Debian/Ubuntu systems: 86 | 87 | `sudo apt install -y rpm fakeroot binutils` 88 | 89 | The Lark binaries can be built from source using 90 | 91 | `./gradlew jpackage` 92 | 93 | When updating to the latest HEAD 94 | 95 | `git pull --recurse-submodules` 96 | 97 | The release binaries are reproducible (pre codesigning and installer packaging). 98 | 99 | 100 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH= 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/args/DisplayAddressCommand.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp.args; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.Parameter; 5 | import com.beust.jcommander.Parameters; 6 | import com.fasterxml.jackson.annotation.JsonInclude; 7 | import com.sparrowwallet.drongo.KeyDerivation; 8 | import com.sparrowwallet.drongo.OutputDescriptor; 9 | import com.sparrowwallet.lark.Lark; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | @Parameters(commandDescription = "Display an address") 15 | public class DisplayAddressCommand extends AbstractCommand { 16 | @Parameter(names = { "--desc" }, description = "Output descriptor e.g. wpkh([00000000/84h/0h/0h]xpub.../0/0), where 00000000 must match --fingerprint and xpub can be obtained with getxpub") 17 | public String desc; 18 | 19 | @Parameter(names = { "--path" }, description = "The BIP 32 derivation path of the key embedded in the address") 20 | public String path; 21 | 22 | @Parameter(names = { "--addr-type" }, description = "The address type to display") 23 | public AddrType addrType = AddrType.wit; 24 | 25 | @Override 26 | public String getName() { 27 | return "displayaddress"; 28 | } 29 | 30 | @Override 31 | public void run(JCommander jCommander, Lark lark, Args args) throws Exception { 32 | super.run(jCommander, lark, args); 33 | 34 | if(desc == null && path == null) { 35 | error("Either --desc or --path must be specified"); 36 | } 37 | 38 | String address; 39 | Map existingRegistrations = new HashMap<>(lark.getWalletRegistrations()); 40 | if(desc != null) { 41 | OutputDescriptor outputDescriptor; 42 | try { 43 | outputDescriptor = OutputDescriptor.getOutputDescriptor(desc); 44 | } catch(Exception e) { 45 | error(e.getMessage()); 46 | return; 47 | } 48 | 49 | if(args.devicePath != null) { 50 | address = lark.displayAddress(args.deviceType, args.devicePath, outputDescriptor); 51 | } else if(args.fingerprint != null) { 52 | address = lark.displayAddress(args.fingerprint, outputDescriptor); 53 | } else { 54 | address = lark.displayAddress(args.deviceType, outputDescriptor); 55 | } 56 | } else { 57 | try { 58 | path = KeyDerivation.writePath(KeyDerivation.parsePath(path)); 59 | } catch(Exception e) { 60 | error("Invalid BIP32 path: " + path); 61 | return; 62 | } 63 | 64 | if(args.devicePath != null) { 65 | address = lark.displaySinglesigAddress(args.deviceType, args.devicePath, path, addrType.getScriptType()); 66 | } else if(args.fingerprint != null) { 67 | address = lark.displaySinglesigAddress(args.fingerprint, path, addrType.getScriptType()); 68 | } else { 69 | address = lark.displaySinglesigAddress(args.deviceType, path, addrType.getScriptType()); 70 | } 71 | } 72 | 73 | Map newRegistrations = getNewRegistrations(lark, existingRegistrations); 74 | value(new AddressValue(address, newRegistrations)); 75 | } 76 | 77 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 78 | private record AddressValue(String address, Map registrations) {} 79 | } 80 | -------------------------------------------------------------------------------- /src/main/deploy/package/linux/lark.spec: -------------------------------------------------------------------------------- 1 | Summary: lark 2 | Name: lark 3 | Version: 1.1.0 4 | Release: 1 5 | License: Unknown 6 | Vendor: Unknown 7 | 8 | %if "x" != "x" 9 | URL: 10 | %endif 11 | 12 | %if "x/opt" != "x" 13 | Prefix: /opt 14 | %endif 15 | 16 | Provides: lark 17 | 18 | %if "x" != "x" 19 | Group: 20 | %endif 21 | 22 | Autoprov: 0 23 | Autoreq: 0 24 | %if "x" != "x" || "x" != "x" 25 | Requires: 26 | %endif 27 | 28 | #comment line below to enable effective jar compression 29 | #it could easily get your package size from 40 to 15Mb but 30 | #build time will substantially increase and it may require unpack200/system java to install 31 | %define __jar_repack %{nil} 32 | 33 | # on RHEL we got unwanted improved debugging enhancements 34 | %define _build_id_links none 35 | 36 | %define package_filelist %{_builddir}/%{name}.files 37 | %define app_filelist %{_builddir}/%{name}.app.files 38 | %define filesystem_filelist %{_builddir}/%{name}.filesystem.files 39 | 40 | %define default_filesystem / /opt /usr /usr/bin /usr/lib /usr/local /usr/local/bin /usr/local/lib 41 | 42 | %description 43 | lark 44 | 45 | %global __os_install_post %{nil} 46 | 47 | %prep 48 | 49 | %build 50 | 51 | %install 52 | rm -rf %{buildroot} 53 | install -d -m 755 %{buildroot}/opt/lark 54 | cp -r %{_sourcedir}/opt/lark/* %{buildroot}/opt/lark 55 | if [ "$(echo %{_sourcedir}/lib/systemd/system/*.service)" != '%{_sourcedir}/lib/systemd/system/*.service' ]; then 56 | install -d -m 755 %{buildroot}/lib/systemd/system 57 | cp %{_sourcedir}/lib/systemd/system/*.service %{buildroot}/lib/systemd/system 58 | fi 59 | %if "x" != "x" 60 | %define license_install_file %{_defaultlicensedir}/%{name}-%{version}/%{basename:} 61 | install -d -m 755 "%{buildroot}%{dirname:%{license_install_file}}" 62 | install -m 644 "" "%{buildroot}%{license_install_file}" 63 | %endif 64 | (cd %{buildroot} && find . -path ./lib/systemd -prune -o -type d -print) | sed -e 's/^\.//' -e '/^$/d' | sort > %{app_filelist} 65 | { rpm -ql filesystem || echo %{default_filesystem}; } | sort > %{filesystem_filelist} 66 | comm -23 %{app_filelist} %{filesystem_filelist} > %{package_filelist} 67 | sed -i -e 's/.*/%dir "&"/' %{package_filelist} 68 | (cd %{buildroot} && find . -not -type d) | sed -e 's/^\.//' -e 's/.*/"&"/' >> %{package_filelist} 69 | %if "x" != "x" 70 | sed -i -e 's|"%{license_install_file}"||' -e '/^$/d' %{package_filelist} 71 | %endif 72 | 73 | %files -f %{package_filelist} 74 | %if "x" != "x" 75 | %license "%{license_install_file}" 76 | %endif 77 | 78 | %post 79 | package_type=rpm 80 | 81 | # Install udev rules 82 | install -m 644 /opt/lark/lib/runtime/conf/udev/*.rules /etc/udev/rules.d 83 | 84 | # Reload udev rules 85 | udevadm control --reload 86 | 87 | # Optionally trigger udev rules 88 | udevadm trigger 89 | 90 | # Make sure the plugdev group exists 91 | groupadd -f plugdev 92 | 93 | # Make sure the current user is added to plugdev 94 | usermod -aG plugdev `whoami` 95 | 96 | 97 | %pre 98 | package_type=rpm 99 | file_belongs_to_single_package () 100 | { 101 | if [ ! -e "$1" ]; then 102 | false 103 | elif [ "$package_type" = rpm ]; then 104 | test `rpm -q --whatprovides "$1" | wc -l` = 1 105 | elif [ "$package_type" = deb ]; then 106 | test `dpkg -S "$1" | wc -l` = 1 107 | else 108 | exit 1 109 | fi 110 | } 111 | 112 | 113 | do_if_file_belongs_to_single_package () 114 | { 115 | local file="$1" 116 | shift 117 | 118 | if file_belongs_to_single_package "$file"; then 119 | "$@" 120 | fi 121 | } 122 | 123 | if [ "$1" -gt 1 ]; then 124 | :; 125 | fi 126 | 127 | %preun 128 | package_type=rpm 129 | file_belongs_to_single_package () 130 | { 131 | if [ ! -e "$1" ]; then 132 | false 133 | elif [ "$package_type" = rpm ]; then 134 | test `rpm -q --whatprovides "$1" | wc -l` = 1 135 | elif [ "$package_type" = deb ]; then 136 | test `dpkg -S "$1" | wc -l` = 1 137 | else 138 | exit 1 139 | fi 140 | } 141 | 142 | 143 | do_if_file_belongs_to_single_package () 144 | { 145 | local file="$1" 146 | shift 147 | 148 | if file_belongs_to_single_package "$file"; then 149 | "$@" 150 | fi 151 | } 152 | # 153 | # Remove $1 desktop file from the list of default handlers for $2 mime type 154 | # in $3 file dumping output to stdout. 155 | # 156 | desktop_filter_out_default_mime_handler () 157 | { 158 | local defaults_list="$3" 159 | 160 | local desktop_file="$1" 161 | local mime_type="$2" 162 | 163 | awk -f- "$defaults_list" < "$tmpfile1" 216 | 217 | local v 218 | local update= 219 | for mime in "$@"; do 220 | desktop_filter_out_default_mime_handler "$desktop_file" "$mime" "$tmpfile1" > "$tmpfile2" 221 | v="$tmpfile2" 222 | tmpfile2="$tmpfile1" 223 | tmpfile1="$v" 224 | 225 | if ! diff -q "$tmpfile1" "$tmpfile2" > /dev/null; then 226 | update=yes 227 | desktop_trace Remove $desktop_file default handler for $mime mime type from $defaults_list file 228 | fi 229 | done 230 | 231 | if [ -n "$update" ]; then 232 | cat "$tmpfile1" > "$defaults_list" 233 | desktop_trace "$defaults_list" file updated 234 | fi 235 | 236 | rm -f "$tmpfile1" "$tmpfile2" 237 | } 238 | 239 | 240 | # 241 | # Remove $1 desktop file from the list of default handlers for $@ mime types 242 | # in all known system defaults lists. 243 | # 244 | desktop_uninstall_default_mime_handler () 245 | { 246 | for f in /usr/share/applications/defaults.list /usr/local/share/applications/defaults.list; do 247 | desktop_uninstall_default_mime_handler_0 "$f" "$@" 248 | done 249 | } 250 | 251 | 252 | desktop_trace () 253 | { 254 | echo "$@" 255 | } 256 | 257 | 258 | 259 | 260 | %clean 261 | -------------------------------------------------------------------------------- /src/main/java/com/sparrowwallet/larkapp/LarkCli.java: -------------------------------------------------------------------------------- 1 | package com.sparrowwallet.larkapp; 2 | 3 | import com.beust.jcommander.JCommander; 4 | import com.beust.jcommander.ParameterException; 5 | import com.fasterxml.jackson.core.JsonProcessingException; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import com.sparrowwallet.drongo.*; 8 | import com.sparrowwallet.lark.DeviceException; 9 | import com.sparrowwallet.lark.Lark; 10 | import com.sparrowwallet.larkapp.args.*; 11 | import org.slf4j.Logger; 12 | import org.slf4j.event.Level; 13 | 14 | import java.util.*; 15 | 16 | public class LarkCli { 17 | private static final Logger log = org.slf4j.LoggerFactory.getLogger(LarkCli.class); 18 | 19 | public static final String APP_NAME = "Lark"; 20 | public static final Version APP_VERSION = new Version("1.1.0"); 21 | 22 | public static void main(String[] argv) throws Exception { 23 | Lark.setConsoleOutput(true); 24 | 25 | List commands = List.of( 26 | new EnumerateCommand(), 27 | new PromptPinCommand(), 28 | new SendPinCommand(), 29 | new GetXpubCommand(), 30 | new GetMasterXpubCommand(), 31 | new SignTxCommand(), 32 | new SignMessageCommand(), 33 | new DisplayAddressCommand(), 34 | new TogglePassphraseCommand()); 35 | 36 | Args args = new Args(); 37 | JCommander.Builder jCommanderBuilder = JCommander.newBuilder() 38 | .addObject(args) 39 | .programName(OsType.getCurrent() == OsType.MACOS ? APP_NAME : APP_NAME.toLowerCase(Locale.ROOT)); 40 | for(Command command : commands) { 41 | jCommanderBuilder.addCommand(command.getName(), command); 42 | } 43 | JCommander jCommander = jCommanderBuilder.build(); 44 | 45 | try { 46 | jCommander.parse(argv); 47 | } catch(ParameterException e) { 48 | showErrorAndExit(e.getMessage()); 49 | } 50 | 51 | if(args.help) { 52 | jCommander.usage(); 53 | System.exit(0); 54 | } 55 | 56 | if(args.version) { 57 | System.out.println(APP_NAME + " " + APP_VERSION.get()); 58 | System.exit(0); 59 | } 60 | 61 | if(args.level != null) { 62 | Drongo.setRootLogLevel(args.level); 63 | } else if(args.debug) { 64 | Drongo.setRootLogLevel(Level.DEBUG); 65 | } 66 | 67 | if(args.network != null) { 68 | Network.set(args.network); 69 | } else if(args.chain != null) { 70 | Network.set(args.chain.getNetwork()); 71 | } 72 | 73 | Lark lark = new Lark(); 74 | if(args.passphrase != null) { 75 | lark.setPassphrase(args.passphrase); 76 | } 77 | 78 | if(args.emulators) { 79 | System.err.println("Emulators are not currently supported"); 80 | System.exit(1); 81 | } 82 | 83 | if(args.walletRegistration != null) { 84 | if(args.walletDescriptor == null || args.walletName == null) { 85 | System.err.println("If `--wallet-registration` is provided, `--wallet-descriptor` and `--wallet-name` must also be provided"); 86 | System.exit(1); 87 | } 88 | OutputDescriptor walletDescriptor = getWalletDescriptor(args); 89 | byte[] walletRegistration = getWalletRegistration(args); 90 | lark.addWalletRegistration(walletDescriptor, args.walletName, walletRegistration); 91 | } else if(args.walletName != null) { 92 | if(args.walletDescriptor == null) { 93 | System.err.println("If `--wallet-name` is provided, `--wallet-descriptor` must also be provided"); 94 | System.exit(1); 95 | } 96 | OutputDescriptor walletDescriptor = getWalletDescriptor(args); 97 | lark.addWalletName(walletDescriptor, args.walletName); 98 | } 99 | 100 | if(args.stdin) { 101 | List stdinArgs = new ArrayList<>(); 102 | try(Scanner scanner = new Scanner(System.in)) { 103 | while(scanner.hasNextLine()) { 104 | String line = scanner.nextLine().trim(); 105 | if(line.isEmpty()) { 106 | break; 107 | } 108 | 109 | Collections.addAll(stdinArgs, line.split("\\s+")); 110 | } 111 | } 112 | try { 113 | jCommander.parse(stdinArgs.toArray(new String[0])); 114 | } catch(ParameterException e) { 115 | showErrorAndExit(e.getMessage()); 116 | } 117 | } 118 | 119 | if(jCommander.getParsedCommand() == null) { 120 | jCommander.usage(); 121 | } else { 122 | try { 123 | for(Command command : commands) { 124 | if(command.getName().equals(jCommander.getParsedCommand())) { 125 | command.run(jCommander, lark, args); 126 | } 127 | } 128 | } catch(DeviceException e) { 129 | showErrorAndExit(e.getMessage()); 130 | } 131 | } 132 | } 133 | 134 | private static OutputDescriptor getWalletDescriptor(Args args) { 135 | try { 136 | return OutputDescriptor.getOutputDescriptor(args.walletDescriptor); 137 | } catch(Exception e) { 138 | System.err.println("Invalid wallet descriptor: " + e.getMessage()); 139 | System.exit(1); 140 | return null; 141 | } 142 | } 143 | 144 | private static byte[] getWalletRegistration(Args args) { 145 | try { 146 | return Utils.hexToBytes(args.walletRegistration); 147 | } catch(Exception e) { 148 | System.err.println("Invalid wallet registration: " + e.getMessage()); 149 | System.exit(1); 150 | return null; 151 | } 152 | } 153 | 154 | public static void showSuccess(boolean success) { 155 | try { 156 | ObjectMapper objectMapper = new ObjectMapper(); 157 | System.out.println(objectMapper.writeValueAsString(new Success(success))); 158 | } catch(JsonProcessingException e) { 159 | log.error("Failed to serialize error", e); 160 | } 161 | } 162 | 163 | public static void showValue(Object value) { 164 | try { 165 | ObjectMapper objectMapper = new ObjectMapper(); 166 | System.out.println(objectMapper.writeValueAsString(value)); 167 | } catch(JsonProcessingException e) { 168 | log.error("Failed to serialize error", e); 169 | } 170 | } 171 | 172 | public static void showErrorAndExit(String errorMessage) { 173 | try { 174 | ObjectMapper objectMapper = new ObjectMapper(); 175 | System.err.println(objectMapper.writeValueAsString(new Error(errorMessage))); 176 | System.exit(1); 177 | } catch(JsonProcessingException e) { 178 | log.error("Failed to serialize error", e); 179 | } 180 | } 181 | 182 | private record Success(boolean success) { 183 | } 184 | 185 | private record Error(String error) { 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH="\\\"\\\"" 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | if ! command -v java >/dev/null 2>&1 137 | then 138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 139 | 140 | Please set the JAVA_HOME variable in your environment to match the 141 | location of your Java installation." 142 | fi 143 | fi 144 | 145 | # Increase the maximum file descriptors if we can. 146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 147 | case $MAX_FD in #( 148 | max*) 149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 150 | # shellcheck disable=SC2039,SC3045 151 | MAX_FD=$( ulimit -H -n ) || 152 | warn "Could not query maximum file descriptor limit" 153 | esac 154 | case $MAX_FD in #( 155 | '' | soft) :;; #( 156 | *) 157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 158 | # shellcheck disable=SC2039,SC3045 159 | ulimit -n "$MAX_FD" || 160 | warn "Could not set maximum file descriptor limit to $MAX_FD" 161 | esac 162 | fi 163 | 164 | # Collect all arguments for the java command, stacking in reverse order: 165 | # * args from the command line 166 | # * the main class name 167 | # * -classpath 168 | # * -D...appname settings 169 | # * --module-path (only if needed) 170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 171 | 172 | # For Cygwin or MSYS, switch paths to Windows format before running java 173 | if "$cygwin" || "$msys" ; then 174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 176 | 177 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 178 | 179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 180 | for arg do 181 | if 182 | case $arg in #( 183 | -*) false ;; # don't mess with options #( 184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 185 | [ -e "$t" ] ;; #( 186 | *) false ;; 187 | esac 188 | then 189 | arg=$( cygpath --path --ignore --mixed "$arg" ) 190 | fi 191 | # Roll the args list around exactly as many times as the number of 192 | # args, so each arg winds up back in the position where it started, but 193 | # possibly modified. 194 | # 195 | # NB: a `for` loop captures its iteration list before it begins, so 196 | # changing the positional parameters here affects neither the number of 197 | # iterations, nor the values presented in `arg`. 198 | shift # remove old arg 199 | set -- "$@" "$arg" # push replacement arg 200 | done 201 | fi 202 | 203 | 204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 206 | 207 | # Collect all arguments for the java command: 208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 209 | # and any embedded shellness will be escaped. 210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 211 | # treated as '${Hostname}' itself on the command line. 212 | 213 | set -- \ 214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 215 | -classpath "$CLASSPATH" \ 216 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ 217 | "$@" 218 | 219 | # Stop when "xargs" is not available. 220 | if ! command -v xargs >/dev/null 2>&1 221 | then 222 | die "xargs is not available" 223 | fi 224 | 225 | # Use "xargs" to parse quoted args. 226 | # 227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 228 | # 229 | # In Bash we could simply go: 230 | # 231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 232 | # set -- "${ARGS[@]}" "$@" 233 | # 234 | # but POSIX shell has neither arrays nor command substitution, so instead we 235 | # post-process each arg (as a line of input to sed) to backslash-escape any 236 | # character that might be a shell metacharacter, then use eval to reverse 237 | # that process (while maintaining the separation between arguments), and wrap 238 | # the whole thing up as a single "set" statement. 239 | # 240 | # This will of course break if any of these variables contains a newline or 241 | # an unmatched quote. 242 | # 243 | 244 | eval "set -- $( 245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 246 | xargs -n1 | 247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 248 | tr '\n' ' ' 249 | )" '"$@"' 250 | 251 | exec "$JAVACMD" "$@" 252 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | --------------------------------------------------------------------------------