示例#1
0
        internal byte[] ToBytes()
        {
            MemoryStream ms = new MemoryStream();

            ms.WriteByte((byte)OperationMode);
            ms.WriteByte((byte)DongleFeatures);
            ms.WriteByte(AcceptedP2PKHVersion);
            ms.WriteByte(AcceptedP2SHVersion);
            var bytes = UserPin.ToBytes();

            ms.WriteByte((byte)bytes.Length);
            ms.Write(bytes, 0, bytes.Length);
            bytes = SecondaryUserPin == null ? new UserPin().ToBytes() : SecondaryUserPin.ToBytes();
            ms.WriteByte((byte)bytes.Length);
            ms.Write(bytes, 0, bytes.Length);

            bytes = RestoredSeed ?? new byte[0];
            ms.WriteByte((byte)bytes.Length);
            ms.Write(bytes, 0, bytes.Length);

            bytes = RestoredWrappingKey == null ? new byte[0] : RestoredWrappingKey.ToBytes();
            ms.WriteByte((byte)bytes.Length);
            ms.Write(bytes, 0, bytes.Length);
            return(ms.ToArray());
        }
        public byte[] UntrustedHashSign(KeyPath keyPath, UserPin pin, LockTime lockTime, SigHash sigHashType)
        {
            MemoryStream data = new MemoryStream();

            byte[] path = Serializer.Serialize(keyPath);
            BufferUtils.WriteBuffer(data, path);

            var pinBytes = pin == null ? new byte[0] : pin.ToBytes();

            data.WriteByte((byte)pinBytes.Length);
            BufferUtils.WriteBuffer(data, pinBytes);
            BufferUtils.WriteUint32BE(data, (uint)lockTime);
            data.WriteByte((byte)sigHashType);
            return(CreateAPDU(LedgerWalletConstants.LedgerWallet_CLA, LedgerWalletConstants.LedgerWallet_INS_HASH_SIGN, (byte)0x00, (byte)0x00, data.ToArray()));
        }
        public bool VerifyPin(UserPin pin, out int remaining)
        {
            remaining = 3;
            var response = ExchangeSingleAPDU(LedgerWalletConstants.LedgerWallet_CLA, LedgerWalletConstants.LedgerWallet_INS_VERIFY_PIN, 0, 0, pin.ToBytes()).GetAwaiter().GetResult();

            if (response.SW == LedgerWalletConstants.SW_OK)
            {
                return(true);
            }
            if (response.SW == LedgerWalletConstants.SW_INS_NOT_SUPPORTED)
            {
                Throw(response.SW);
            }
            remaining = (response.SW & 0x0F);
            return(false);
        }
        public async Task <VerifyPinResult> VerifyPinAsync(UserPin pin, CancellationToken cancellation = default(CancellationToken))
        {
            var retVal = new VerifyPinResult();

            var response = await ExchangeSingleAPDUAsync(LedgerWalletConstants.LedgerWallet_CLA, LedgerWalletConstants.LedgerWallet_INS_VERIFY_PIN, 0, 0, pin.ToBytes(), cancellation);

            if (response.SW == LedgerWalletConstants.SW_OK)
            {
                retVal.IsSuccess = true;
                return(retVal);
            }

            if (response.SW == LedgerWalletConstants.SW_INS_NOT_SUPPORTED)
            {
                Throw(response.SW);
            }

            retVal.Remaining = (response.SW & 0x0F);
            return(retVal);
        }
示例#5
0
        public bool VerifyPin(UserPin pin)
        {
            int remain;

            return(VerifyPin(pin, out remain));
        }
        public TransactionSignature UntrustedHashSign(KeyPath keyPath, UserPin pin, LockTime lockTime, SigHash sigHashType)
        {
            using(Transport.Lock())
            {
                MemoryStream data = new MemoryStream();
                byte[] path = Serializer.Serialize(keyPath);
                BufferUtils.WriteBuffer(data, path);

                var pinBytes = pin == null ? new byte[0] : pin.ToBytes();
                data.WriteByte((byte)pinBytes.Length);
                BufferUtils.WriteBuffer(data, pinBytes);
                BufferUtils.WriteUint32BE(data, (uint)lockTime);
                data.WriteByte((byte)sigHashType);
                byte[] response = ExchangeApdu(LedgerWalletConstants.LedgerWallet_CLA, LedgerWalletConstants.LedgerWallet_INS_HASH_SIGN, (byte)0x00, (byte)0x00, data.ToArray(), OK);
                response[0] = (byte)0x30;
                return new TransactionSignature(response);
            }
        }
 public bool VerifyPin(UserPin pin)
 {
     int remain;
     return VerifyPin(pin, out remain);
 }
 public bool VerifyPin(UserPin pin, out int remaining)
 {
     using(Transport.Lock())
     {
         int lastSW;
         remaining = 3;
         var response = ExchangeApdu(LedgerWalletConstants.LedgerWallet_CLA, LedgerWalletConstants.LedgerWallet_INS_VERIFY_PIN, 0, 0, pin.ToBytes(), out lastSW);
         if(lastSW == LedgerWalletConstants.SW_OK)
             return true;
         if(lastSW == LedgerWalletConstants.SW_INS_NOT_SUPPORTED)
             Throw(lastSW);
         remaining = (lastSW & 0x0F);
         return false;
     }
 }