@airgap/bitcoin 0.13.11-beta.1 → 0.13.11-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -0
- package/index.js +18 -0
- package/index.js.map +1 -0
- package/package.json +1 -5
- package/v0/index.d.ts +14 -0
- package/v0/index.js +34 -0
- package/v0/index.js.map +1 -0
- package/v0/protocol/BitcoinAddress.d.ts +9 -0
- package/v0/protocol/BitcoinAddress.js +23 -0
- package/v0/protocol/BitcoinAddress.js.map +1 -0
- package/v0/protocol/BitcoinCryptoClient.d.ts +11 -0
- package/v0/protocol/BitcoinCryptoClient.js +91 -0
- package/v0/protocol/BitcoinCryptoClient.js.map +1 -0
- package/v0/protocol/BitcoinProtocol.d.ts +167 -0
- package/v0/protocol/BitcoinProtocol.js +1063 -0
- package/v0/protocol/BitcoinProtocol.js.map +1 -0
- package/v0/protocol/BitcoinProtocolOptions.d.ts +26 -0
- package/v0/protocol/BitcoinProtocolOptions.js +148 -0
- package/v0/protocol/BitcoinProtocolOptions.js.map +1 -0
- package/v0/protocol/BitcoinSegwitAddress.d.ts +7 -0
- package/v0/protocol/BitcoinSegwitAddress.js +41 -0
- package/v0/protocol/BitcoinSegwitAddress.js.map +1 -0
- package/v0/protocol/BitcoinSegwitProtocol.d.ts +28 -0
- package/v0/protocol/BitcoinSegwitProtocol.js +541 -0
- package/v0/protocol/BitcoinSegwitProtocol.js.map +1 -0
- package/v0/protocol/BitcoinTestnetProtocol.d.ts +7 -0
- package/v0/protocol/BitcoinTestnetProtocol.js +58 -0
- package/v0/protocol/BitcoinTestnetProtocol.js.map +1 -0
- package/v0/protocol/BitcoinTypes.d.ts +21 -0
- package/v0/protocol/BitcoinTypes.js +3 -0
- package/v0/protocol/BitcoinTypes.js.map +1 -0
- package/v0/serializer/schemas/v2/transaction-sign-request-bitcoin-segwit.json +0 -0
- package/v0/serializer/schemas/v2/transaction-sign-request-bitcoin.json +73 -0
- package/v0/serializer/schemas/v2/transaction-sign-response-bitcoin-segwit.json +0 -0
- package/v0/serializer/schemas/v2/transaction-sign-response-bitcoin.json +37 -0
- package/v0/serializer/schemas/v3/transaction-sign-request-bitcoin-segwit.json +29 -0
- package/v0/serializer/schemas/v3/transaction-sign-request-bitcoin.json +73 -0
- package/v0/serializer/schemas/v3/transaction-sign-response-bitcoin-segwit.json +19 -0
- package/v0/serializer/schemas/v3/transaction-sign-response-bitcoin.json +37 -0
- package/v0/serializer/validators/transaction-validator.d.ts +15 -0
- package/v0/serializer/validators/transaction-validator.js +81 -0
- package/v0/serializer/validators/transaction-validator.js.map +1 -0
- package/v0/serializer/validators/validators.d.ts +1 -0
- package/v0/serializer/validators/validators.js +151 -0
- package/v0/serializer/validators/validators.js.map +1 -0
- package/v0/types/signed-transaction-bitcoin-segwit.d.ts +5 -0
- package/v0/types/signed-transaction-bitcoin-segwit.js +3 -0
- package/v0/types/signed-transaction-bitcoin-segwit.js.map +1 -0
- package/v0/types/signed-transaction-bitcoin.d.ts +9 -0
- package/v0/types/signed-transaction-bitcoin.js +3 -0
- package/v0/types/signed-transaction-bitcoin.js.map +1 -0
- package/v0/types/transaction-bitcoin.d.ts +20 -0
- package/v0/types/transaction-bitcoin.js +3 -0
- package/v0/types/transaction-bitcoin.js.map +1 -0
- package/v0/types/unsigned-transaction-bitcoin-segwit.d.ts +7 -0
- package/v0/types/unsigned-transaction-bitcoin-segwit.js +3 -0
- package/v0/types/unsigned-transaction-bitcoin-segwit.js.map +1 -0
- package/v0/types/unsigned-transaction-bitcoin.d.ts +22 -0
- package/v0/types/unsigned-transaction-bitcoin.js +3 -0
- package/v0/types/unsigned-transaction-bitcoin.js.map +1 -0
- package/v1/block-explorer/BlockCypherBlockExplorer.d.ts +9 -0
- package/v1/block-explorer/BlockCypherBlockExplorer.js +74 -0
- package/v1/block-explorer/BlockCypherBlockExplorer.js.map +1 -0
- package/v1/data/BitcoinAddress.d.ts +7 -0
- package/v1/data/BitcoinAddress.js +20 -0
- package/v1/data/BitcoinAddress.js.map +1 -0
- package/v1/data/BitcoinSegwitAddress.d.ts +8 -0
- package/v1/data/BitcoinSegwitAddress.js +25 -0
- package/v1/data/BitcoinSegwitAddress.js.map +1 -0
- package/v1/index.d.ts +20 -0
- package/v1/index.js +24 -0
- package/v1/index.js.map +1 -0
- package/v1/module/BitcoinModule.d.ts +16 -0
- package/v1/module/BitcoinModule.js +112 -0
- package/v1/module/BitcoinModule.js.map +1 -0
- package/v1/module.d.ts +3 -0
- package/v1/module.js +24 -0
- package/v1/module.js.map +1 -0
- package/v1/protocol/BitcoinCryptoClient.d.ts +12 -0
- package/v1/protocol/BitcoinCryptoClient.js +96 -0
- package/v1/protocol/BitcoinCryptoClient.js.map +1 -0
- package/v1/protocol/BitcoinProtocol.d.ts +72 -0
- package/v1/protocol/BitcoinProtocol.js +1193 -0
- package/v1/protocol/BitcoinProtocol.js.map +1 -0
- package/v1/protocol/BitcoinSegwitProtocol.d.ts +52 -0
- package/v1/protocol/BitcoinSegwitProtocol.js +720 -0
- package/v1/protocol/BitcoinSegwitProtocol.js.map +1 -0
- package/v1/protocol/BitcoinTestnetProtocol.d.ts +12 -0
- package/v1/protocol/BitcoinTestnetProtocol.js +73 -0
- package/v1/protocol/BitcoinTestnetProtocol.js.map +1 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +13 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +75 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin-segwit.d.ts +4 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin-segwit.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin-segwit.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin.d.ts +4 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin-segwit.d.ts +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin-segwit.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin-segwit.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin.d.ts +7 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin.js.map +1 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-bitcoin-segwit.json +29 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-bitcoin.json +79 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-bitcoin-segwit.json +19 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-bitcoin.json +37 -0
- package/v1/serializer/v3/serializer-companion.d.ts +14 -0
- package/v1/serializer/v3/serializer-companion.js +197 -0
- package/v1/serializer/v3/serializer-companion.js.map +1 -0
- package/v1/serializer/v3/validators/transaction-validator.d.ts +7 -0
- package/v1/serializer/v3/validators/transaction-validator.js +56 -0
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
- package/v1/serializer/v3/validators/validators.d.ts +7 -0
- package/v1/serializer/v3/validators/validators.js +238 -0
- package/v1/serializer/v3/validators/validators.js.map +1 -0
- package/v1/types/bitcoinjs.d.ts +14 -0
- package/v1/types/bitcoinjs.js +3 -0
- package/v1/types/bitcoinjs.js.map +1 -0
- package/v1/types/crypto.d.ts +2 -0
- package/v1/types/crypto.js +3 -0
- package/v1/types/crypto.js.map +1 -0
- package/v1/types/indexer.d.ts +81 -0
- package/v1/types/indexer.js +3 -0
- package/v1/types/indexer.js.map +1 -0
- package/v1/types/key.d.ts +6 -0
- package/v1/types/key.js +3 -0
- package/v1/types/key.js.map +1 -0
- package/v1/types/protocol.d.ts +17 -0
- package/v1/types/protocol.js +3 -0
- package/v1/types/protocol.js.map +1 -0
- package/v1/types/transaction.d.ts +39 -0
- package/v1/types/transaction.js +3 -0
- package/v1/types/transaction.js.map +1 -0
- package/v1/utils/common.d.ts +2 -0
- package/v1/utils/common.js +28 -0
- package/v1/utils/common.js.map +1 -0
- package/v1/utils/key.d.ts +34 -0
- package/v1/utils/key.js +190 -0
- package/v1/utils/key.js.map +1 -0
- package/v1/utils/network.d.ts +2 -0
- package/v1/utils/network.js +22 -0
- package/v1/utils/network.js.map +1 -0
- package/v1/utils/signature.d.ts +2 -0
- package/v1/utils/signature.js +34 -0
- package/v1/utils/signature.js.map +1 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.BitcoinV3SerializerCompanion = void 0;
|
|
40
|
+
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
41
|
+
var validate_1 = require("@airgap/coinlib-core/dependencies/src/validate.js-0.13.1/validate");
|
|
42
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
43
|
+
var serializer_1 = require("@airgap/serializer");
|
|
44
|
+
var transaction_converter_1 = require("./schemas/converter/transaction-converter");
|
|
45
|
+
var transaction_validator_1 = require("./validators/transaction-validator");
|
|
46
|
+
var validators_1 = require("./validators/validators");
|
|
47
|
+
var bitcoinTransactionSignRequest = require('./schemas/generated/transaction-sign-request-bitcoin.json');
|
|
48
|
+
var bitcoinTransactionSignResponse = require('./schemas/generated/transaction-sign-response-bitcoin.json');
|
|
49
|
+
var bitcoinSegwitTransactionSignRequest = require('./schemas/generated/transaction-sign-request-bitcoin-segwit.json');
|
|
50
|
+
var bitcoinSegwitTransactionSignResponse = require('./schemas/generated/transaction-sign-response-bitcoin-segwit.json');
|
|
51
|
+
var BitcoinV3SerializerCompanion = /** @class */ (function () {
|
|
52
|
+
function BitcoinV3SerializerCompanion() {
|
|
53
|
+
this.schemas = [
|
|
54
|
+
{
|
|
55
|
+
type: serializer_1.IACMessageType.TransactionSignRequest,
|
|
56
|
+
schema: { schema: bitcoinTransactionSignRequest },
|
|
57
|
+
protocolIdentifier: coinlib_core_1.MainProtocolSymbols.BTC
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: serializer_1.IACMessageType.TransactionSignResponse,
|
|
61
|
+
schema: { schema: bitcoinTransactionSignResponse },
|
|
62
|
+
protocolIdentifier: coinlib_core_1.MainProtocolSymbols.BTC
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: serializer_1.IACMessageType.TransactionSignRequest,
|
|
66
|
+
schema: { schema: bitcoinSegwitTransactionSignRequest },
|
|
67
|
+
protocolIdentifier: coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: serializer_1.IACMessageType.TransactionSignResponse,
|
|
71
|
+
schema: { schema: bitcoinSegwitTransactionSignResponse },
|
|
72
|
+
protocolIdentifier: coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
this.bitcoinTransactionValidator = new transaction_validator_1.BitcoinTransactionValidator();
|
|
76
|
+
Object.keys(validators_1.bitcoinValidators).forEach(function (key) {
|
|
77
|
+
validate_1.validators[key] = validators_1.bitcoinValidators[key];
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
BitcoinV3SerializerCompanion.prototype.toTransactionSignRequest = function (identifier, unsignedTransaction, publicKey, callbackUrl) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
switch (identifier) {
|
|
84
|
+
case coinlib_core_1.MainProtocolSymbols.BTC:
|
|
85
|
+
return [2 /*return*/, (0, transaction_converter_1.bitcoinUnsignedTransactionToRequest)(unsignedTransaction, publicKey, callbackUrl)];
|
|
86
|
+
case coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT:
|
|
87
|
+
return [2 /*return*/, (0, transaction_converter_1.bitcoinSegwitUnsignedTransactionToRequest)(unsignedTransaction, publicKey, callbackUrl)];
|
|
88
|
+
default:
|
|
89
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.BITCOIN, "Protocol ".concat(identifier, " not supported"));
|
|
90
|
+
}
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
BitcoinV3SerializerCompanion.prototype.fromTransactionSignRequest = function (identifier, transactionSignRequest) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (identifier) {
|
|
99
|
+
case coinlib_core_1.MainProtocolSymbols.BTC:
|
|
100
|
+
return [2 /*return*/, (0, transaction_converter_1.bitcoinTransactionSignRequestToUnsigned)(transactionSignRequest)];
|
|
101
|
+
case coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT:
|
|
102
|
+
return [2 /*return*/, (0, transaction_converter_1.bitcoinSegwitTransactionSignRequestToUnsigned)(transactionSignRequest)];
|
|
103
|
+
default:
|
|
104
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.BITCOIN, "Protocol ".concat(identifier, " not supported"));
|
|
105
|
+
}
|
|
106
|
+
return [2 /*return*/];
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
BitcoinV3SerializerCompanion.prototype.validateTransactionSignRequest = function (identifier, transactionSignRequest) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
var _a, _b;
|
|
113
|
+
return __generator(this, function (_c) {
|
|
114
|
+
switch (_c.label) {
|
|
115
|
+
case 0:
|
|
116
|
+
_a = identifier;
|
|
117
|
+
switch (_a) {
|
|
118
|
+
case coinlib_core_1.MainProtocolSymbols.BTC: return [3 /*break*/, 1];
|
|
119
|
+
case coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT: return [3 /*break*/, 4];
|
|
120
|
+
}
|
|
121
|
+
return [3 /*break*/, 5];
|
|
122
|
+
case 1:
|
|
123
|
+
_c.trys.push([1, 3, , 4]);
|
|
124
|
+
return [4 /*yield*/, this.bitcoinTransactionValidator.validateUnsignedTransaction(transactionSignRequest)];
|
|
125
|
+
case 2:
|
|
126
|
+
_c.sent();
|
|
127
|
+
return [2 /*return*/, true];
|
|
128
|
+
case 3:
|
|
129
|
+
_b = _c.sent();
|
|
130
|
+
return [2 /*return*/, false];
|
|
131
|
+
case 4: return [2 /*return*/, true];
|
|
132
|
+
case 5: throw new errors_1.UnsupportedError(coinlib_core_1.Domain.BITCOIN, "Protocol ".concat(identifier, " not supported"));
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
BitcoinV3SerializerCompanion.prototype.toTransactionSignResponse = function (identifier, signedTransaction, accountIdentifier) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
+
return __generator(this, function (_a) {
|
|
140
|
+
switch (identifier) {
|
|
141
|
+
case coinlib_core_1.MainProtocolSymbols.BTC:
|
|
142
|
+
return [2 /*return*/, (0, transaction_converter_1.bitcoinSignedTransactionToResponse)(signedTransaction, accountIdentifier)];
|
|
143
|
+
case coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT:
|
|
144
|
+
return [2 /*return*/, (0, transaction_converter_1.bitcoinSegwitSignedTransactionToResponse)(signedTransaction, accountIdentifier)];
|
|
145
|
+
default:
|
|
146
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.BITCOIN, "Protocol ".concat(identifier, " not supported"));
|
|
147
|
+
}
|
|
148
|
+
return [2 /*return*/];
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
BitcoinV3SerializerCompanion.prototype.fromTransactionSignResponse = function (identifier, transactionSignResponse) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
154
|
+
return __generator(this, function (_a) {
|
|
155
|
+
switch (identifier) {
|
|
156
|
+
case coinlib_core_1.MainProtocolSymbols.BTC:
|
|
157
|
+
return [2 /*return*/, (0, transaction_converter_1.bitcoinTransactionSignResponseToSigned)(transactionSignResponse)];
|
|
158
|
+
case coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT:
|
|
159
|
+
return [2 /*return*/, (0, transaction_converter_1.bitcoinSegwitTransactionSignResponseToSigned)(transactionSignResponse)];
|
|
160
|
+
default:
|
|
161
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.BITCOIN, "Protocol ".concat(identifier, " not supported"));
|
|
162
|
+
}
|
|
163
|
+
return [2 /*return*/];
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
BitcoinV3SerializerCompanion.prototype.validateTransactionSignResponse = function (identifier, transactionSignResponse) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
169
|
+
var _a, _b;
|
|
170
|
+
return __generator(this, function (_c) {
|
|
171
|
+
switch (_c.label) {
|
|
172
|
+
case 0:
|
|
173
|
+
_a = identifier;
|
|
174
|
+
switch (_a) {
|
|
175
|
+
case coinlib_core_1.MainProtocolSymbols.BTC: return [3 /*break*/, 1];
|
|
176
|
+
case coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT: return [3 /*break*/, 4];
|
|
177
|
+
}
|
|
178
|
+
return [3 /*break*/, 5];
|
|
179
|
+
case 1:
|
|
180
|
+
_c.trys.push([1, 3, , 4]);
|
|
181
|
+
return [4 /*yield*/, this.bitcoinTransactionValidator.validateSignedTransaction(transactionSignResponse)];
|
|
182
|
+
case 2:
|
|
183
|
+
_c.sent();
|
|
184
|
+
return [2 /*return*/, true];
|
|
185
|
+
case 3:
|
|
186
|
+
_b = _c.sent();
|
|
187
|
+
return [2 /*return*/, false];
|
|
188
|
+
case 4: return [2 /*return*/, true];
|
|
189
|
+
case 5: throw new errors_1.UnsupportedError(coinlib_core_1.Domain.BITCOIN, "Protocol ".concat(identifier, " not supported"));
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
return BitcoinV3SerializerCompanion;
|
|
195
|
+
}());
|
|
196
|
+
exports.BitcoinV3SerializerCompanion = BitcoinV3SerializerCompanion;
|
|
197
|
+
//# sourceMappingURL=serializer-companion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer-companion.js","sourceRoot":"","sources":["../../../../src/v1/serializer/v3/serializer-companion.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAkE;AAClE,8FAA8F;AAC9F,sDAA8D;AAG9D,iDAAgH;AAShH,mFASkD;AAElD,4EAAgF;AAChF,sDAA2D;AAE3D,IAAM,6BAA6B,GAAe,OAAO,CAAC,2DAA2D,CAAC,CAAA;AACtH,IAAM,8BAA8B,GAAe,OAAO,CAAC,4DAA4D,CAAC,CAAA;AAExH,IAAM,mCAAmC,GAAe,OAAO,CAAC,kEAAkE,CAAC,CAAA;AACnI,IAAM,oCAAoC,GAAe,OAAO,CAAC,mEAAmE,CAAC,CAAA;AAErI;IA0BE;QAzBgB,YAAO,GAA4B;YACjD;gBACE,IAAI,EAAE,2BAAc,CAAC,sBAAsB;gBAC3C,MAAM,EAAE,EAAE,MAAM,EAAE,6BA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AAxC,UACE,UAAkB,EAClB,uBAAgD;;;gBAEhD,QAAQ,UAAU,EAAE;oBAClB,KAAK,kCAAmB,CAAC,GAAG;wBAC1B,sBAAO,IAAA,8DAAsC,EAAC,uBAAyD,CAAC,EAAA;oBAC1G,KAAK,kCAAmB,CAAC,UAAU;wBACjC,sBAAO,IAAA,oEAA4C,EAAC,uBAAyD,CAAC,EAAA;oBAChH;wBACE,MAAM,IAAI,yBAAgB,CAAC,qBAAM,CAAC,OAAO,EAAE,mBAAY,UAAU,mBAAgB,CAAC,CAAA;iBACrF;;;;KACF;IAEY,sEAA+B,GAA5C,UAA6C,UAAkB,EAAE,uBAAgD;;;;;;wBACvG,KAAA,UAAU,CAAA;;iCACX,kCAAmB,CAAC,GAAG,CAAC,CAAxB,wBAAuB;iCAQvB,kCAAmB,CAAC,UAAU,CAAC,CAA/B,wBAA8B;;;;;wBAN/B,qBAAM,IAAI,CAAC,2BAA2B,CAAC,yBAAyB,CAAC,uBAAyD,CAAC,EAAA;;wBAA3H,SAA2H,CAAA;wBAE3H,sBAAO,IAAI,EAAA;;;wBAEX,sBAAO,KAAK,EAAA;4BAGd,sBAAO,IAAI,EAAA;4BAEX,MAAM,IAAI,yBAAgB,CAAC,qBAAM,CAAC,OAAO,EAAE,mBAAY,UAAU,mBAAgB,CAAC,CAAA;;;;KAEvF;IACH,mCAAC;AAAD,CAAC,AA5HD,IA4HC;AA5HY,oEAA4B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TransactionValidator } from '@airgap/serializer';
|
|
2
|
+
import { BitcoinTransactionSignRequest } from '../schemas/definitions/transaction-sign-request-bitcoin';
|
|
3
|
+
import { BitcoinTransactionSignResponse } from '../schemas/definitions/transaction-sign-response-bitcoin';
|
|
4
|
+
export declare class BitcoinTransactionValidator implements TransactionValidator {
|
|
5
|
+
validateUnsignedTransaction(request: BitcoinTransactionSignRequest): Promise<any>;
|
|
6
|
+
validateSignedTransaction(response: BitcoinTransactionSignResponse): Promise<any>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BitcoinTransactionValidator = void 0;
|
|
4
|
+
// tslint:disable: max-classes-per-file
|
|
5
|
+
var validate_1 = require("@airgap/coinlib-core/dependencies/src/validate.js-0.13.1/validate");
|
|
6
|
+
var serializer_1 = require("@airgap/serializer");
|
|
7
|
+
var unsignedTransactionConstraints = {
|
|
8
|
+
ins: {
|
|
9
|
+
presence: { allowEmpty: false },
|
|
10
|
+
isValidBitcoinInput: true
|
|
11
|
+
},
|
|
12
|
+
outs: {
|
|
13
|
+
presence: { allowEmpty: false },
|
|
14
|
+
isValidBitcoinOutput: true
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var signedTransactionConstraints = {
|
|
18
|
+
from: {
|
|
19
|
+
presence: { allowEmpty: false },
|
|
20
|
+
isValidBitcoinFromArray: true
|
|
21
|
+
},
|
|
22
|
+
amount: {
|
|
23
|
+
type: 'BigNumber',
|
|
24
|
+
presence: { allowEmpty: false }
|
|
25
|
+
},
|
|
26
|
+
fee: {
|
|
27
|
+
type: 'BigNumber',
|
|
28
|
+
presence: { allowEmpty: false }
|
|
29
|
+
},
|
|
30
|
+
accountIdentifier: {
|
|
31
|
+
type: 'String',
|
|
32
|
+
presence: { allowEmpty: false }
|
|
33
|
+
},
|
|
34
|
+
transaction: {
|
|
35
|
+
isValidBitcoinTxString: true,
|
|
36
|
+
type: 'String',
|
|
37
|
+
presence: { allowEmpty: false }
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var success = function () { return undefined; };
|
|
41
|
+
var error = function (errors) { return errors; };
|
|
42
|
+
var BitcoinTransactionValidator = /** @class */ (function () {
|
|
43
|
+
function BitcoinTransactionValidator() {
|
|
44
|
+
}
|
|
45
|
+
BitcoinTransactionValidator.prototype.validateUnsignedTransaction = function (request) {
|
|
46
|
+
var transaction = request.transaction;
|
|
47
|
+
(0, serializer_1.validateSyncScheme)({});
|
|
48
|
+
return (0, validate_1.async)(transaction, unsignedTransactionConstraints).then(success, error);
|
|
49
|
+
};
|
|
50
|
+
BitcoinTransactionValidator.prototype.validateSignedTransaction = function (response) {
|
|
51
|
+
return (0, validate_1.async)(response, signedTransactionConstraints).then(success, error);
|
|
52
|
+
};
|
|
53
|
+
return BitcoinTransactionValidator;
|
|
54
|
+
}());
|
|
55
|
+
exports.BitcoinTransactionValidator = BitcoinTransactionValidator;
|
|
56
|
+
//# sourceMappingURL=transaction-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-validator.js","sourceRoot":"","sources":["../../../../../src/v1/serializer/v3/validators/transaction-validator.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,8FAAyF;AACzF,iDAA6E;AAK7E,IAAM,8BAA8B,GAAG;IACrC,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;QAC/B,mBAAmB,EAAE,IAAI;KAC1B;IACD,IAAI,EAAE;QACJ,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;QAC/B,oBAAoB,EAAE,IAAI;KAC3B;CACF,CAAA;AAED,IAAM,4BAA4B,GAAG;IACnC,IAAI,EAAE;QACJ,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;QAC/B,uBAAuB,EAAE,IAAI;KAC9B;IACD,MAAM,EAAE;QACN,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;KAChC;IACD,GAAG,EAAE;QACH,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;KAChC;IACD,iBAAiB,EAAE;QACjB,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;KAChC;IACD,WAAW,EAAE;QACX,sBAAsB,EAAE,IAAI;QAC5B,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;KAChC;CACF,CAAA;AACD,IAAM,OAAO,GAAG,cAAM,OAAA,SAAS,EAAT,CAAS,CAAA;AAC/B,IAAM,KAAK,GAAG,UAAC,MAAM,IAAK,OAAA,MAAM,EAAN,CAAM,CAAA;AAEhC;IAAA;IAUA,CAAC;IATQ,iEAA2B,GAAlC,UAAmC,OAAsC;QACvE,IAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAA;QACvC,IAAA,+BAAkB,EAAC,EAAE,CAAC,CAAA;QAEtB,OAAO,IAAA,gBAAK,EAAC,WAAW,EAAE,8BAA8B,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAChF,CAAC;IACM,+DAAyB,GAAhC,UAAiC,QAAwC;QACvE,OAAO,IAAA,gBAAK,EAAC,QAAQ,EAAE,4BAA4B,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC3E,CAAC;IACH,kCAAC;AAAD,CAAC,AAVD,IAUC;AAVY,kEAA2B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const bitcoinValidators: {
|
|
2
|
+
isValidBitcoinInput: (ins: unknown) => Promise<"not an array" | "doesn't have property txId " | "not a valid txId" | "doesn't have property value " | "value not a valid BigNumber" | "doesn't have property vout" | "vout is not a number" | "vout is not a positive value" | "doesn't have property address " | "not a valid bitcoin address" | null>;
|
|
3
|
+
isValidBitcoinOutput: (outs: unknown) => Promise<"not an array" | "doesn't have property value " | "doesn't have property recipient" | "invalid Bitcoin address" | "doesn't have property isChange " | "change is not a boolean" | "value is not BigNumber" | null>;
|
|
4
|
+
isValidBitcoinFromArray: (array: unknown) => Promise<"not a valid bitcoin address" | "not an array of Bitcoin addresses" | null>;
|
|
5
|
+
isBitcoinAccount: (accountIdentifier: string) => Promise<"not a valid Bitcoin account" | null>;
|
|
6
|
+
isValidBitcoinTxString: (transaction: string) => "is not a valid hex encoded Bitcoin transaction" | null;
|
|
7
|
+
};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.bitcoinValidators = void 0;
|
|
43
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
44
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
45
|
+
var BitcoinProtocol_1 = require("../../../protocol/BitcoinProtocol");
|
|
46
|
+
exports.bitcoinValidators = {
|
|
47
|
+
isValidBitcoinInput: function (ins) { return __awaiter(void 0, void 0, void 0, function () {
|
|
48
|
+
var i, value, pattern, protocol, metadata, pattern;
|
|
49
|
+
var _a, _b, _c;
|
|
50
|
+
return __generator(this, function (_d) {
|
|
51
|
+
switch (_d.label) {
|
|
52
|
+
case 0:
|
|
53
|
+
// if (!Array.isArray(ins)) {
|
|
54
|
+
// ins = [ins]
|
|
55
|
+
// }
|
|
56
|
+
if (!Array.isArray(ins)) {
|
|
57
|
+
return [2 /*return*/, 'not an array'];
|
|
58
|
+
}
|
|
59
|
+
i = 0;
|
|
60
|
+
_d.label = 1;
|
|
61
|
+
case 1:
|
|
62
|
+
if (!(i < ins.length)) return [3 /*break*/, 5];
|
|
63
|
+
value = ins[i];
|
|
64
|
+
if (!value.hasOwnProperty('txId')) {
|
|
65
|
+
return [2 /*return*/, "doesn't have property txId "];
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
pattern = RegExp('^[a-fA-F0-9]{64}$');
|
|
69
|
+
if (!pattern.test(value.txId)) {
|
|
70
|
+
return [2 /*return*/, 'not a valid txId'];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!value.hasOwnProperty('value')) {
|
|
74
|
+
return [2 /*return*/, "doesn't have property value "];
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if (!bignumber_1.default.isBigNumber(value.value)) {
|
|
78
|
+
return [2 /*return*/, 'value not a valid BigNumber'];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!value.hasOwnProperty('vout')) {
|
|
82
|
+
return [2 /*return*/, "doesn't have property vout"];
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
if (typeof value.vout !== 'number') {
|
|
86
|
+
return [2 /*return*/, 'vout is not a number'];
|
|
87
|
+
}
|
|
88
|
+
else if (value.vout < 0) {
|
|
89
|
+
return [2 /*return*/, 'vout is not a positive value'];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!!value.hasOwnProperty('address')) return [3 /*break*/, 2];
|
|
93
|
+
return [2 /*return*/, "doesn't have property address "];
|
|
94
|
+
case 2:
|
|
95
|
+
protocol = (0, BitcoinProtocol_1.createBitcoinProtocol)();
|
|
96
|
+
return [4 /*yield*/, protocol.getMetadata()];
|
|
97
|
+
case 3:
|
|
98
|
+
metadata = _d.sent();
|
|
99
|
+
pattern = RegExp((_c = (_b = (_a = metadata.account) === null || _a === void 0 ? void 0 : _a.address) === null || _b === void 0 ? void 0 : _b.regex) !== null && _c !== void 0 ? _c : '.*');
|
|
100
|
+
if (!pattern.test(value.address)) {
|
|
101
|
+
return [2 /*return*/, 'not a valid bitcoin address'];
|
|
102
|
+
}
|
|
103
|
+
_d.label = 4;
|
|
104
|
+
case 4:
|
|
105
|
+
i++;
|
|
106
|
+
return [3 /*break*/, 1];
|
|
107
|
+
case 5: return [2 /*return*/, null];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}); },
|
|
111
|
+
isValidBitcoinOutput: function (outs) { return __awaiter(void 0, void 0, void 0, function () {
|
|
112
|
+
var i, value, protocol, metadata, pattern;
|
|
113
|
+
var _a, _b, _c;
|
|
114
|
+
return __generator(this, function (_d) {
|
|
115
|
+
switch (_d.label) {
|
|
116
|
+
case 0:
|
|
117
|
+
// console.log(outs)
|
|
118
|
+
// if (!Array.isArray(outs)) {
|
|
119
|
+
// outs = [outs]
|
|
120
|
+
// }
|
|
121
|
+
if (!Array.isArray(outs)) {
|
|
122
|
+
return [2 /*return*/, 'not an array'];
|
|
123
|
+
}
|
|
124
|
+
i = 0;
|
|
125
|
+
_d.label = 1;
|
|
126
|
+
case 1:
|
|
127
|
+
if (!(i < outs.length)) return [3 /*break*/, 6];
|
|
128
|
+
value = outs[i];
|
|
129
|
+
if (!!value.hasOwnProperty('recipient')) return [3 /*break*/, 2];
|
|
130
|
+
return [2 /*return*/, "doesn't have property recipient"];
|
|
131
|
+
case 2:
|
|
132
|
+
protocol = (0, BitcoinProtocol_1.createBitcoinProtocol)();
|
|
133
|
+
return [4 /*yield*/, protocol.getMetadata()];
|
|
134
|
+
case 3:
|
|
135
|
+
metadata = _d.sent();
|
|
136
|
+
pattern = RegExp((_c = (_b = (_a = metadata.account) === null || _a === void 0 ? void 0 : _a.address) === null || _b === void 0 ? void 0 : _b.regex) !== null && _c !== void 0 ? _c : '.*');
|
|
137
|
+
if (!pattern.test(value.recipient)) {
|
|
138
|
+
return [2 /*return*/, 'invalid Bitcoin address'];
|
|
139
|
+
}
|
|
140
|
+
_d.label = 4;
|
|
141
|
+
case 4:
|
|
142
|
+
if (!value.hasOwnProperty('isChange')) {
|
|
143
|
+
return [2 /*return*/, "doesn't have property isChange "];
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
if (typeof value.isChange !== 'boolean') {
|
|
147
|
+
return [2 /*return*/, 'change is not a boolean'];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!value.hasOwnProperty('value')) {
|
|
151
|
+
return [2 /*return*/, "doesn't have property value "];
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
if (!bignumber_1.default.isBigNumber(value.value)) {
|
|
155
|
+
return [2 /*return*/, 'value is not BigNumber'];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
_d.label = 5;
|
|
159
|
+
case 5:
|
|
160
|
+
i++;
|
|
161
|
+
return [3 /*break*/, 1];
|
|
162
|
+
case 6: return [2 /*return*/, null];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}); },
|
|
166
|
+
isValidBitcoinFromArray: function (array) { return __awaiter(void 0, void 0, void 0, function () {
|
|
167
|
+
var i, address, protocol, metadata, pattern;
|
|
168
|
+
var _a, _b, _c;
|
|
169
|
+
return __generator(this, function (_d) {
|
|
170
|
+
switch (_d.label) {
|
|
171
|
+
case 0:
|
|
172
|
+
if (!Array.isArray(array)) {
|
|
173
|
+
return [2 /*return*/, 'not an array of Bitcoin addresses'];
|
|
174
|
+
}
|
|
175
|
+
i = 0;
|
|
176
|
+
_d.label = 1;
|
|
177
|
+
case 1:
|
|
178
|
+
if (!(i < array.length)) return [3 /*break*/, 4];
|
|
179
|
+
address = array[i];
|
|
180
|
+
protocol = (0, BitcoinProtocol_1.createBitcoinProtocol)();
|
|
181
|
+
return [4 /*yield*/, protocol.getMetadata()];
|
|
182
|
+
case 2:
|
|
183
|
+
metadata = _d.sent();
|
|
184
|
+
pattern = RegExp((_c = (_b = (_a = metadata.account) === null || _a === void 0 ? void 0 : _a.address) === null || _b === void 0 ? void 0 : _b.regex) !== null && _c !== void 0 ? _c : '.*');
|
|
185
|
+
if (!pattern.test(address)) {
|
|
186
|
+
return [2 /*return*/, 'not a valid bitcoin address'];
|
|
187
|
+
}
|
|
188
|
+
_d.label = 3;
|
|
189
|
+
case 3:
|
|
190
|
+
i++;
|
|
191
|
+
return [3 /*break*/, 1];
|
|
192
|
+
case 4: return [2 /*return*/, null];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}); },
|
|
196
|
+
isBitcoinAccount: function (accountIdentifier) { return __awaiter(void 0, void 0, void 0, function () {
|
|
197
|
+
var protocol, derivedKey, error_1;
|
|
198
|
+
return __generator(this, function (_a) {
|
|
199
|
+
switch (_a.label) {
|
|
200
|
+
case 0:
|
|
201
|
+
if (accountIdentifier === null || typeof accountIdentifier === 'undefined') {
|
|
202
|
+
return [2 /*return*/, null];
|
|
203
|
+
}
|
|
204
|
+
_a.label = 1;
|
|
205
|
+
case 1:
|
|
206
|
+
_a.trys.push([1, 4, , 5]);
|
|
207
|
+
protocol = (0, BitcoinProtocol_1.createBitcoinProtocol)();
|
|
208
|
+
return [4 /*yield*/, protocol.deriveFromExtendedPublicKey((0, module_kit_1.newExtendedPublicKey)(accountIdentifier, 'encoded'), 0, 0)];
|
|
209
|
+
case 2:
|
|
210
|
+
derivedKey = _a.sent();
|
|
211
|
+
return [4 /*yield*/, protocol.getAddressFromPublicKey(derivedKey)];
|
|
212
|
+
case 3:
|
|
213
|
+
_a.sent();
|
|
214
|
+
return [2 /*return*/, null];
|
|
215
|
+
case 4:
|
|
216
|
+
error_1 = _a.sent();
|
|
217
|
+
return [2 /*return*/, 'not a valid Bitcoin account'];
|
|
218
|
+
case 5: return [2 /*return*/];
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}); },
|
|
222
|
+
isValidBitcoinTxString: function (transaction) {
|
|
223
|
+
// allow empty values by default (needs to be checked by "presence" check)
|
|
224
|
+
if (transaction === null || typeof transaction === 'undefined') {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
try {
|
|
228
|
+
var protocol = new BitcoinProtocol_1.BitcoinProtocolImpl();
|
|
229
|
+
var bitcoinJSLib = protocol.bitcoinJS.lib;
|
|
230
|
+
bitcoinJSLib.Transaction.fromHex(transaction);
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
return 'is not a valid hex encoded Bitcoin transaction';
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../../../src/v1/serializer/v3/validators/validators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iHAA0F;AAC1F,iDAAyD;AAEzD,qEAA8F;AAEjF,QAAA,iBAAiB,GAAG;IAC/B,mBAAmB,EAAE,UAAO,GAAY;;;;;;oBACtC,6BAA6B;oBAC7B,gBAAgB;oBAChB,IAAI;oBACJ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;wBACvB,sBAAO,cAAc,EAAA;qBACtB;oBAEQ,CAAC,GAAW,CAAC;;;yBAAE,CAAA,CAAC,GAAG,GAAG,CAAC,MAAM,CAAA;oBAC9B,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;oBACpB,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE;wBACjC,sBAAO,6BAA6B,EAAA;qBACrC;yBAAM;wBACC,OAAO,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAA;wBAC3C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;4BAC7B,sBAAO,kBAAkB,EAAA;yBAC1B;qBACF;oBACD,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE;wBAClC,sBAAO,8BAA8B,EAA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AAC,CAAA;YAE7C,OAAO,IAAI,CAAA;SACZ;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,gDAAgD,CAAA;SACxD;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type * as bitcoin from 'bitcoinjs-lib';
|
|
2
|
+
export interface BitcoinJS {
|
|
3
|
+
lib: any;
|
|
4
|
+
message: any;
|
|
5
|
+
config: {
|
|
6
|
+
network: any;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface BitcoinSegwitJS {
|
|
10
|
+
lib: typeof bitcoin;
|
|
11
|
+
config: {
|
|
12
|
+
network: bitcoin.Network;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitcoinjs.js","sourceRoot":"","sources":["../../../src/v1/types/bitcoinjs.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/v1/types/crypto.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export interface UTXOResponse {
|
|
2
|
+
txid: string;
|
|
3
|
+
vout: number;
|
|
4
|
+
value: string;
|
|
5
|
+
height: number;
|
|
6
|
+
confirmations: number;
|
|
7
|
+
address: string;
|
|
8
|
+
path: string;
|
|
9
|
+
}
|
|
10
|
+
export interface Vin {
|
|
11
|
+
txid: string;
|
|
12
|
+
vout: number;
|
|
13
|
+
sequence: any;
|
|
14
|
+
n: number;
|
|
15
|
+
addresses: string[];
|
|
16
|
+
isAddress: boolean;
|
|
17
|
+
isOwn: boolean;
|
|
18
|
+
value: string;
|
|
19
|
+
hex: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Vout {
|
|
22
|
+
value: string;
|
|
23
|
+
n: number;
|
|
24
|
+
hex: string;
|
|
25
|
+
addresses: string[];
|
|
26
|
+
isAddress: boolean;
|
|
27
|
+
isOwn?: boolean;
|
|
28
|
+
spent?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface Transaction {
|
|
31
|
+
txid: string;
|
|
32
|
+
version: number;
|
|
33
|
+
vin: Vin[];
|
|
34
|
+
vout: Vout[];
|
|
35
|
+
blockHash: string;
|
|
36
|
+
blockHeight: number;
|
|
37
|
+
confirmations: number;
|
|
38
|
+
blockTime: number;
|
|
39
|
+
value: string;
|
|
40
|
+
valueIn: string;
|
|
41
|
+
fees: string;
|
|
42
|
+
hex: string;
|
|
43
|
+
}
|
|
44
|
+
export interface Token {
|
|
45
|
+
type: string;
|
|
46
|
+
name: string;
|
|
47
|
+
path: string;
|
|
48
|
+
transfers: number;
|
|
49
|
+
decimals: number;
|
|
50
|
+
balance: string;
|
|
51
|
+
totalReceived: string;
|
|
52
|
+
totalSent: string;
|
|
53
|
+
}
|
|
54
|
+
export interface XPubResponse {
|
|
55
|
+
page: number;
|
|
56
|
+
totalPages: number;
|
|
57
|
+
itemsOnPage: number;
|
|
58
|
+
address: string;
|
|
59
|
+
balance: string;
|
|
60
|
+
totalReceived: string;
|
|
61
|
+
totalSent: string;
|
|
62
|
+
unconfirmedBalance: string;
|
|
63
|
+
unconfirmedTxs: number;
|
|
64
|
+
txs: number;
|
|
65
|
+
transactions?: Transaction[];
|
|
66
|
+
totalTokens?: number;
|
|
67
|
+
tokens?: Token[];
|
|
68
|
+
}
|
|
69
|
+
export interface AddressResponse {
|
|
70
|
+
page: number;
|
|
71
|
+
totalPages: number;
|
|
72
|
+
itemsOnPage: number;
|
|
73
|
+
address: string;
|
|
74
|
+
balance: string;
|
|
75
|
+
totalReceived: string;
|
|
76
|
+
totalSent: string;
|
|
77
|
+
unconfirmedBalance: string;
|
|
78
|
+
unconfirmedTxs: number;
|
|
79
|
+
txs: number;
|
|
80
|
+
transactions?: Transaction[];
|
|
81
|
+
}
|