@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.
Files changed (148) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +18 -0
  3. package/index.js.map +1 -0
  4. package/package.json +1 -5
  5. package/v0/index.d.ts +14 -0
  6. package/v0/index.js +34 -0
  7. package/v0/index.js.map +1 -0
  8. package/v0/protocol/BitcoinAddress.d.ts +9 -0
  9. package/v0/protocol/BitcoinAddress.js +23 -0
  10. package/v0/protocol/BitcoinAddress.js.map +1 -0
  11. package/v0/protocol/BitcoinCryptoClient.d.ts +11 -0
  12. package/v0/protocol/BitcoinCryptoClient.js +91 -0
  13. package/v0/protocol/BitcoinCryptoClient.js.map +1 -0
  14. package/v0/protocol/BitcoinProtocol.d.ts +167 -0
  15. package/v0/protocol/BitcoinProtocol.js +1063 -0
  16. package/v0/protocol/BitcoinProtocol.js.map +1 -0
  17. package/v0/protocol/BitcoinProtocolOptions.d.ts +26 -0
  18. package/v0/protocol/BitcoinProtocolOptions.js +148 -0
  19. package/v0/protocol/BitcoinProtocolOptions.js.map +1 -0
  20. package/v0/protocol/BitcoinSegwitAddress.d.ts +7 -0
  21. package/v0/protocol/BitcoinSegwitAddress.js +41 -0
  22. package/v0/protocol/BitcoinSegwitAddress.js.map +1 -0
  23. package/v0/protocol/BitcoinSegwitProtocol.d.ts +28 -0
  24. package/v0/protocol/BitcoinSegwitProtocol.js +541 -0
  25. package/v0/protocol/BitcoinSegwitProtocol.js.map +1 -0
  26. package/v0/protocol/BitcoinTestnetProtocol.d.ts +7 -0
  27. package/v0/protocol/BitcoinTestnetProtocol.js +58 -0
  28. package/v0/protocol/BitcoinTestnetProtocol.js.map +1 -0
  29. package/v0/protocol/BitcoinTypes.d.ts +21 -0
  30. package/v0/protocol/BitcoinTypes.js +3 -0
  31. package/v0/protocol/BitcoinTypes.js.map +1 -0
  32. package/v0/serializer/schemas/v2/transaction-sign-request-bitcoin-segwit.json +0 -0
  33. package/v0/serializer/schemas/v2/transaction-sign-request-bitcoin.json +73 -0
  34. package/v0/serializer/schemas/v2/transaction-sign-response-bitcoin-segwit.json +0 -0
  35. package/v0/serializer/schemas/v2/transaction-sign-response-bitcoin.json +37 -0
  36. package/v0/serializer/schemas/v3/transaction-sign-request-bitcoin-segwit.json +29 -0
  37. package/v0/serializer/schemas/v3/transaction-sign-request-bitcoin.json +73 -0
  38. package/v0/serializer/schemas/v3/transaction-sign-response-bitcoin-segwit.json +19 -0
  39. package/v0/serializer/schemas/v3/transaction-sign-response-bitcoin.json +37 -0
  40. package/v0/serializer/validators/transaction-validator.d.ts +15 -0
  41. package/v0/serializer/validators/transaction-validator.js +81 -0
  42. package/v0/serializer/validators/transaction-validator.js.map +1 -0
  43. package/v0/serializer/validators/validators.d.ts +1 -0
  44. package/v0/serializer/validators/validators.js +151 -0
  45. package/v0/serializer/validators/validators.js.map +1 -0
  46. package/v0/types/signed-transaction-bitcoin-segwit.d.ts +5 -0
  47. package/v0/types/signed-transaction-bitcoin-segwit.js +3 -0
  48. package/v0/types/signed-transaction-bitcoin-segwit.js.map +1 -0
  49. package/v0/types/signed-transaction-bitcoin.d.ts +9 -0
  50. package/v0/types/signed-transaction-bitcoin.js +3 -0
  51. package/v0/types/signed-transaction-bitcoin.js.map +1 -0
  52. package/v0/types/transaction-bitcoin.d.ts +20 -0
  53. package/v0/types/transaction-bitcoin.js +3 -0
  54. package/v0/types/transaction-bitcoin.js.map +1 -0
  55. package/v0/types/unsigned-transaction-bitcoin-segwit.d.ts +7 -0
  56. package/v0/types/unsigned-transaction-bitcoin-segwit.js +3 -0
  57. package/v0/types/unsigned-transaction-bitcoin-segwit.js.map +1 -0
  58. package/v0/types/unsigned-transaction-bitcoin.d.ts +22 -0
  59. package/v0/types/unsigned-transaction-bitcoin.js +3 -0
  60. package/v0/types/unsigned-transaction-bitcoin.js.map +1 -0
  61. package/v1/block-explorer/BlockCypherBlockExplorer.d.ts +9 -0
  62. package/v1/block-explorer/BlockCypherBlockExplorer.js +74 -0
  63. package/v1/block-explorer/BlockCypherBlockExplorer.js.map +1 -0
  64. package/v1/data/BitcoinAddress.d.ts +7 -0
  65. package/v1/data/BitcoinAddress.js +20 -0
  66. package/v1/data/BitcoinAddress.js.map +1 -0
  67. package/v1/data/BitcoinSegwitAddress.d.ts +8 -0
  68. package/v1/data/BitcoinSegwitAddress.js +25 -0
  69. package/v1/data/BitcoinSegwitAddress.js.map +1 -0
  70. package/v1/index.d.ts +20 -0
  71. package/v1/index.js +24 -0
  72. package/v1/index.js.map +1 -0
  73. package/v1/module/BitcoinModule.d.ts +16 -0
  74. package/v1/module/BitcoinModule.js +112 -0
  75. package/v1/module/BitcoinModule.js.map +1 -0
  76. package/v1/module.d.ts +3 -0
  77. package/v1/module.js +24 -0
  78. package/v1/module.js.map +1 -0
  79. package/v1/protocol/BitcoinCryptoClient.d.ts +12 -0
  80. package/v1/protocol/BitcoinCryptoClient.js +96 -0
  81. package/v1/protocol/BitcoinCryptoClient.js.map +1 -0
  82. package/v1/protocol/BitcoinProtocol.d.ts +72 -0
  83. package/v1/protocol/BitcoinProtocol.js +1193 -0
  84. package/v1/protocol/BitcoinProtocol.js.map +1 -0
  85. package/v1/protocol/BitcoinSegwitProtocol.d.ts +52 -0
  86. package/v1/protocol/BitcoinSegwitProtocol.js +720 -0
  87. package/v1/protocol/BitcoinSegwitProtocol.js.map +1 -0
  88. package/v1/protocol/BitcoinTestnetProtocol.d.ts +12 -0
  89. package/v1/protocol/BitcoinTestnetProtocol.js +73 -0
  90. package/v1/protocol/BitcoinTestnetProtocol.js.map +1 -0
  91. package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +13 -0
  92. package/v1/serializer/v3/schemas/converter/transaction-converter.js +75 -0
  93. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
  94. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin-segwit.d.ts +4 -0
  95. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin-segwit.js +3 -0
  96. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin-segwit.js.map +1 -0
  97. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin.d.ts +4 -0
  98. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin.js +3 -0
  99. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin.js.map +1 -0
  100. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin-segwit.d.ts +3 -0
  101. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin-segwit.js +3 -0
  102. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin-segwit.js.map +1 -0
  103. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin.d.ts +7 -0
  104. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin.js +3 -0
  105. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin.js.map +1 -0
  106. package/v1/serializer/v3/schemas/generated/transaction-sign-request-bitcoin-segwit.json +29 -0
  107. package/v1/serializer/v3/schemas/generated/transaction-sign-request-bitcoin.json +79 -0
  108. package/v1/serializer/v3/schemas/generated/transaction-sign-response-bitcoin-segwit.json +19 -0
  109. package/v1/serializer/v3/schemas/generated/transaction-sign-response-bitcoin.json +37 -0
  110. package/v1/serializer/v3/serializer-companion.d.ts +14 -0
  111. package/v1/serializer/v3/serializer-companion.js +197 -0
  112. package/v1/serializer/v3/serializer-companion.js.map +1 -0
  113. package/v1/serializer/v3/validators/transaction-validator.d.ts +7 -0
  114. package/v1/serializer/v3/validators/transaction-validator.js +56 -0
  115. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
  116. package/v1/serializer/v3/validators/validators.d.ts +7 -0
  117. package/v1/serializer/v3/validators/validators.js +238 -0
  118. package/v1/serializer/v3/validators/validators.js.map +1 -0
  119. package/v1/types/bitcoinjs.d.ts +14 -0
  120. package/v1/types/bitcoinjs.js +3 -0
  121. package/v1/types/bitcoinjs.js.map +1 -0
  122. package/v1/types/crypto.d.ts +2 -0
  123. package/v1/types/crypto.js +3 -0
  124. package/v1/types/crypto.js.map +1 -0
  125. package/v1/types/indexer.d.ts +81 -0
  126. package/v1/types/indexer.js +3 -0
  127. package/v1/types/indexer.js.map +1 -0
  128. package/v1/types/key.d.ts +6 -0
  129. package/v1/types/key.js +3 -0
  130. package/v1/types/key.js.map +1 -0
  131. package/v1/types/protocol.d.ts +17 -0
  132. package/v1/types/protocol.js +3 -0
  133. package/v1/types/protocol.js.map +1 -0
  134. package/v1/types/transaction.d.ts +39 -0
  135. package/v1/types/transaction.js +3 -0
  136. package/v1/types/transaction.js.map +1 -0
  137. package/v1/utils/common.d.ts +2 -0
  138. package/v1/utils/common.js +28 -0
  139. package/v1/utils/common.js.map +1 -0
  140. package/v1/utils/key.d.ts +34 -0
  141. package/v1/utils/key.js +190 -0
  142. package/v1/utils/key.js.map +1 -0
  143. package/v1/utils/network.d.ts +2 -0
  144. package/v1/utils/network.js +22 -0
  145. package/v1/utils/network.js.map +1 -0
  146. package/v1/utils/signature.d.ts +2 -0
  147. package/v1/utils/signature.js +34 -0
  148. package/v1/utils/signature.js.map +1 -0
@@ -0,0 +1,22 @@
1
+ import { TransactionSignRequest, TransactionSignRequestV2 } from '@airgap/serializer';
2
+ interface IInTransaction {
3
+ txId: string;
4
+ value: string;
5
+ vout: number;
6
+ address: string;
7
+ derivationPath?: string;
8
+ }
9
+ interface IOutTransaction {
10
+ recipient: string;
11
+ isChange: boolean;
12
+ value: string;
13
+ derivationPath?: string;
14
+ }
15
+ interface RawBitcoinTransaction {
16
+ ins: IInTransaction[];
17
+ outs: IOutTransaction[];
18
+ }
19
+ export interface UnsignedBitcoinTransaction extends TransactionSignRequest, TransactionSignRequestV2 {
20
+ transaction: RawBitcoinTransaction;
21
+ }
22
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=unsigned-transaction-bitcoin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unsigned-transaction-bitcoin.js","sourceRoot":"","sources":["../../../src/v0/types/unsigned-transaction-bitcoin.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import { AirGapBlockExplorer, BlockExplorerMetadata } from '@airgap/module-kit';
2
+ export declare class BlockCypherBlockExplorer implements AirGapBlockExplorer {
3
+ readonly url: string;
4
+ constructor(url?: string);
5
+ private readonly metadata;
6
+ getMetadata(): Promise<BlockExplorerMetadata>;
7
+ createAddressUrl(address: string): Promise<string>;
8
+ createTransactionUrl(transactionId: string): Promise<string>;
9
+ }
@@ -0,0 +1,74 @@
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.BlockCypherBlockExplorer = void 0;
40
+ var BLOCK_EXPLORER_MAINNET_URL = 'https://live.blockcypher.com/btc';
41
+ var BlockCypherBlockExplorer = /** @class */ (function () {
42
+ function BlockCypherBlockExplorer(url) {
43
+ if (url === void 0) { url = BLOCK_EXPLORER_MAINNET_URL; }
44
+ this.url = url;
45
+ this.metadata = {
46
+ name: 'BlockCypher',
47
+ url: this.url
48
+ };
49
+ }
50
+ BlockCypherBlockExplorer.prototype.getMetadata = function () {
51
+ return __awaiter(this, void 0, void 0, function () {
52
+ return __generator(this, function (_a) {
53
+ return [2 /*return*/, this.metadata];
54
+ });
55
+ });
56
+ };
57
+ BlockCypherBlockExplorer.prototype.createAddressUrl = function (address) {
58
+ return __awaiter(this, void 0, void 0, function () {
59
+ return __generator(this, function (_a) {
60
+ return [2 /*return*/, "".concat(this.url, "/address/").concat(address, "/")];
61
+ });
62
+ });
63
+ };
64
+ BlockCypherBlockExplorer.prototype.createTransactionUrl = function (transactionId) {
65
+ return __awaiter(this, void 0, void 0, function () {
66
+ return __generator(this, function (_a) {
67
+ return [2 /*return*/, "".concat(this.url, "/tx/").concat(transactionId)];
68
+ });
69
+ });
70
+ };
71
+ return BlockCypherBlockExplorer;
72
+ }());
73
+ exports.BlockCypherBlockExplorer = BlockCypherBlockExplorer;
74
+ //# sourceMappingURL=BlockCypherBlockExplorer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlockCypherBlockExplorer.js","sourceRoot":"","sources":["../../../src/v1/block-explorer/BlockCypherBlockExplorer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,0BAA0B,GAAW,kCAAkC,CAAA;AAE7E;IACE,kCAAmC,GAAwC;QAAxC,oBAAA,EAAA,gCAAwC;QAAxC,QAAG,GAAH,GAAG,CAAqC;QAE1D,aAAQ,GAA0B;YACjD,IAAI,EAAE,aAAa;YACnB,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAA;IAL6E,CAAC;IAOlE,8CAAW,GAAxB;;;gBACE,sBAAO,IAAI,CAAC,QAAQ,EAAA;;;KACrB;IAEY,mDAAgB,GAA7B,UAA8B,OAAe;;;gBAC3C,sBAAO,UAAG,IAAI,CAAC,GAAG,sBAAY,OAAO,MAAG,EAAA;;;KACzC;IAEY,uDAAoB,GAAjC,UAAkC,aAAqB;;;gBACrD,sBAAO,UAAG,IAAI,CAAC,GAAG,iBAAO,aAAa,CAAE,EAAA;;;KACzC;IACH,+BAAC;AAAD,CAAC,AAnBD,IAmBC;AAnBY,4DAAwB"}
@@ -0,0 +1,7 @@
1
+ export declare class BitcoinAddress {
2
+ protected readonly value: string;
3
+ private constructor();
4
+ static fromHDNode(node: any): BitcoinAddress;
5
+ static fromECPair(keyPair: any): BitcoinAddress;
6
+ asString(): string;
7
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BitcoinAddress = void 0;
4
+ var BitcoinAddress = /** @class */ (function () {
5
+ function BitcoinAddress(value) {
6
+ this.value = value;
7
+ }
8
+ BitcoinAddress.fromHDNode = function (node) {
9
+ return new BitcoinAddress(node.getAddress());
10
+ };
11
+ BitcoinAddress.fromECPair = function (keyPair) {
12
+ return new BitcoinAddress(keyPair.getAddress());
13
+ };
14
+ BitcoinAddress.prototype.asString = function () {
15
+ return this.value;
16
+ };
17
+ return BitcoinAddress;
18
+ }());
19
+ exports.BitcoinAddress = BitcoinAddress;
20
+ //# sourceMappingURL=BitcoinAddress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitcoinAddress.js","sourceRoot":"","sources":["../../../src/v1/data/BitcoinAddress.ts"],"names":[],"mappings":";;;AAAA;IACE,wBAAuC,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAE1C,yBAAU,GAAxB,UAAyB,IAAS;QAChC,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAA;IAC9C,CAAC;IAEa,yBAAU,GAAxB,UAAyB,OAAY;QACnC,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;IACjD,CAAC;IAEM,iCAAQ,GAAf;QACE,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IACH,qBAAC;AAAD,CAAC,AAdD,IAcC;AAdY,wCAAc"}
@@ -0,0 +1,8 @@
1
+ import type * as bitcoin from 'bitcoinjs-lib';
2
+ export declare class BitcoinSegwitAddress {
3
+ protected readonly value: string;
4
+ private constructor();
5
+ static fromBip32(bip32: bitcoin.BIP32Interface): BitcoinSegwitAddress;
6
+ static fromPayment(payment: bitcoin.Payment): BitcoinSegwitAddress;
7
+ asString(): string;
8
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BitcoinSegwitAddress = void 0;
4
+ var coinlib_core_1 = require("@airgap/coinlib-core");
5
+ var errors_1 = require("@airgap/coinlib-core/errors");
6
+ var BitcoinSegwitAddress = /** @class */ (function () {
7
+ function BitcoinSegwitAddress(value) {
8
+ this.value = value;
9
+ }
10
+ BitcoinSegwitAddress.fromBip32 = function (bip32) {
11
+ return new BitcoinSegwitAddress(bip32.toBase58());
12
+ };
13
+ BitcoinSegwitAddress.fromPayment = function (payment) {
14
+ if (payment.address === undefined) {
15
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.BITCOIN, 'Could not generate address.');
16
+ }
17
+ return new BitcoinSegwitAddress(payment.address);
18
+ };
19
+ BitcoinSegwitAddress.prototype.asString = function () {
20
+ return this.value;
21
+ };
22
+ return BitcoinSegwitAddress;
23
+ }());
24
+ exports.BitcoinSegwitAddress = BitcoinSegwitAddress;
25
+ //# sourceMappingURL=BitcoinSegwitAddress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitcoinSegwitAddress.js","sourceRoot":"","sources":["../../../src/v1/data/BitcoinSegwitAddress.ts"],"names":[],"mappings":";;;AAAA,qDAA6C;AAC7C,sDAA8D;AAG9D;IACE,8BAAuC,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAE1C,8BAAS,GAAvB,UAAwB,KAA6B;QACnD,OAAO,IAAI,oBAAoB,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;IACnD,CAAC;IAEa,gCAAW,GAAzB,UAA0B,OAAwB;QAChD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE;YACjC,MAAM,IAAI,yBAAgB,CAAC,qBAAM,CAAC,OAAO,EAAE,6BAA6B,CAAC,CAAA;SAC1E;QAED,OAAO,IAAI,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAClD,CAAC;IAEM,uCAAQ,GAAf;QACE,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IACH,2BAAC;AAAD,CAAC,AAlBD,IAkBC;AAlBY,oDAAoB"}
package/v1/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { BlockCypherBlockExplorer } from './block-explorer/BlockCypherBlockExplorer';
2
+ import { BitcoinModule } from './module/BitcoinModule';
3
+ import { BitcoinProtocol, createBitcoinProtocol, createBitcoinProtocolOptions } from './protocol/BitcoinProtocol';
4
+ import { BitcoinSegwitProtocol, createBitcoinSegwitProtocol } from './protocol/BitcoinSegwitProtocol';
5
+ import { BitcoinTestnetProtocol, createBitcoinTestnetProtocol } from './protocol/BitcoinTestnetProtocol';
6
+ import { bitcoinSignedTransactionToResponse, bitcoinTransactionSignRequestToUnsigned, bitcoinTransactionSignResponseToSigned, bitcoinUnsignedTransactionToRequest } from './serializer/v3/schemas/converter/transaction-converter';
7
+ import { BitcoinTransactionSignRequest } from './serializer/v3/schemas/definitions/transaction-sign-request-bitcoin';
8
+ import { BitcoinSegwitTransactionSignRequest } from './serializer/v3/schemas/definitions/transaction-sign-request-bitcoin-segwit';
9
+ import { BitcoinTransactionSignResponse } from './serializer/v3/schemas/definitions/transaction-sign-response-bitcoin';
10
+ import { BitcoinSegwitTransactionSignResponse } from './serializer/v3/schemas/definitions/transaction-sign-response-bitcoin-segwit';
11
+ import { BitcoinTransactionValidator } from './serializer/v3/validators/transaction-validator';
12
+ import { bitcoinValidators } from './serializer/v3/validators/validators';
13
+ import { BitcoinCryptoConfiguration } from './types/crypto';
14
+ import { BitcoinProtocolNetwork, BitcoinProtocolOptions, BitcoinUnits } from './types/protocol';
15
+ import { BitcoinInTransaction, BitcoinOutTransaction, BitcoinSegwitSignedTransaction, BitcoinSegwitUnsignedTransaction, BitcoinSignedTransaction, BitcoinTransactionCursor, BitcoinUnsignedTransaction } from './types/transaction';
16
+ export { BitcoinModule };
17
+ export { BitcoinProtocol, BitcoinTestnetProtocol, BitcoinSegwitProtocol, createBitcoinProtocol, createBitcoinTestnetProtocol, createBitcoinSegwitProtocol, createBitcoinProtocolOptions };
18
+ export { BlockCypherBlockExplorer };
19
+ export { BitcoinCryptoConfiguration, BitcoinUnits, BitcoinProtocolNetwork, BitcoinProtocolOptions, BitcoinUnsignedTransaction, BitcoinSignedTransaction, BitcoinSegwitUnsignedTransaction, BitcoinSegwitSignedTransaction, BitcoinInTransaction, BitcoinOutTransaction, BitcoinTransactionCursor };
20
+ export { BitcoinTransactionSignRequest, BitcoinTransactionSignResponse, BitcoinSegwitTransactionSignRequest, BitcoinSegwitTransactionSignResponse, BitcoinTransactionValidator, bitcoinValidators, bitcoinUnsignedTransactionToRequest, bitcoinSignedTransactionToResponse, bitcoinTransactionSignRequestToUnsigned, bitcoinTransactionSignResponseToSigned };
package/v1/index.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bitcoinTransactionSignResponseToSigned = exports.bitcoinTransactionSignRequestToUnsigned = exports.bitcoinSignedTransactionToResponse = exports.bitcoinUnsignedTransactionToRequest = exports.bitcoinValidators = exports.BitcoinTransactionValidator = exports.BlockCypherBlockExplorer = exports.createBitcoinProtocolOptions = exports.createBitcoinSegwitProtocol = exports.createBitcoinTestnetProtocol = exports.createBitcoinProtocol = exports.BitcoinModule = void 0;
4
+ var BlockCypherBlockExplorer_1 = require("./block-explorer/BlockCypherBlockExplorer");
5
+ Object.defineProperty(exports, "BlockCypherBlockExplorer", { enumerable: true, get: function () { return BlockCypherBlockExplorer_1.BlockCypherBlockExplorer; } });
6
+ var BitcoinModule_1 = require("./module/BitcoinModule");
7
+ Object.defineProperty(exports, "BitcoinModule", { enumerable: true, get: function () { return BitcoinModule_1.BitcoinModule; } });
8
+ var BitcoinProtocol_1 = require("./protocol/BitcoinProtocol");
9
+ Object.defineProperty(exports, "createBitcoinProtocol", { enumerable: true, get: function () { return BitcoinProtocol_1.createBitcoinProtocol; } });
10
+ Object.defineProperty(exports, "createBitcoinProtocolOptions", { enumerable: true, get: function () { return BitcoinProtocol_1.createBitcoinProtocolOptions; } });
11
+ var BitcoinSegwitProtocol_1 = require("./protocol/BitcoinSegwitProtocol");
12
+ Object.defineProperty(exports, "createBitcoinSegwitProtocol", { enumerable: true, get: function () { return BitcoinSegwitProtocol_1.createBitcoinSegwitProtocol; } });
13
+ var BitcoinTestnetProtocol_1 = require("./protocol/BitcoinTestnetProtocol");
14
+ Object.defineProperty(exports, "createBitcoinTestnetProtocol", { enumerable: true, get: function () { return BitcoinTestnetProtocol_1.createBitcoinTestnetProtocol; } });
15
+ var transaction_converter_1 = require("./serializer/v3/schemas/converter/transaction-converter");
16
+ Object.defineProperty(exports, "bitcoinSignedTransactionToResponse", { enumerable: true, get: function () { return transaction_converter_1.bitcoinSignedTransactionToResponse; } });
17
+ Object.defineProperty(exports, "bitcoinTransactionSignRequestToUnsigned", { enumerable: true, get: function () { return transaction_converter_1.bitcoinTransactionSignRequestToUnsigned; } });
18
+ Object.defineProperty(exports, "bitcoinTransactionSignResponseToSigned", { enumerable: true, get: function () { return transaction_converter_1.bitcoinTransactionSignResponseToSigned; } });
19
+ Object.defineProperty(exports, "bitcoinUnsignedTransactionToRequest", { enumerable: true, get: function () { return transaction_converter_1.bitcoinUnsignedTransactionToRequest; } });
20
+ var transaction_validator_1 = require("./serializer/v3/validators/transaction-validator");
21
+ Object.defineProperty(exports, "BitcoinTransactionValidator", { enumerable: true, get: function () { return transaction_validator_1.BitcoinTransactionValidator; } });
22
+ var validators_1 = require("./serializer/v3/validators/validators");
23
+ Object.defineProperty(exports, "bitcoinValidators", { enumerable: true, get: function () { return validators_1.bitcoinValidators; } });
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":";;;AAAA,sFAAoF;AA+C3E,yGA/CA,mDAAwB,OA+CA;AA9CjC,wDAAsD;AA8B7C,8FA9BA,6BAAa,OA8BA;AA7BtB,8DAAiH;AAqC/G,sGArCwB,uCAAqB,OAqCxB;AAGrB,6GAxC+C,8CAA4B,OAwC/C;AAvC9B,0EAAqG;AAsCnG,4GAtC8B,mDAA2B,OAsC9B;AArC7B,4EAAwG;AAoCtG,6GApC+B,qDAA4B,OAoC/B;AAnC9B,iGAKgE;AAiE9D,mHArEA,0DAAkC,OAqEA;AAClC,wHArEA,+DAAuC,OAqEA;AACvC,uHArEA,8DAAsC,OAqEA;AAHtC,oHAjEA,2DAAmC,OAiEA;AA3DrC,0FAA8F;AAyD5F,4GAzDO,mDAA2B,OAyDP;AAxD7B,oEAAyE;AAyDvE,kGAzDO,8BAAiB,OAyDP"}
@@ -0,0 +1,16 @@
1
+ import { MainProtocolSymbols } from '@airgap/coinlib-core';
2
+ import { AirGapBlockExplorer, AirGapModule, AirGapOfflineProtocol, AirGapOnlineProtocol, AirGapV3SerializerCompanion, ProtocolConfiguration } from '@airgap/module-kit';
3
+ declare type SupportedProtocols = MainProtocolSymbols.BTC | MainProtocolSymbols.BTC_SEGWIT;
4
+ export declare class BitcoinModule implements AirGapModule<{
5
+ Protocols: SupportedProtocols;
6
+ }> {
7
+ private readonly networkRegistries;
8
+ readonly supportedProtocols: Record<SupportedProtocols, ProtocolConfiguration>;
9
+ constructor();
10
+ createOfflineProtocol(identifier: SupportedProtocols): Promise<AirGapOfflineProtocol | undefined>;
11
+ createOnlineProtocol(identifier: SupportedProtocols, networkId?: string): Promise<AirGapOnlineProtocol | undefined>;
12
+ createBlockExplorer(identifier: SupportedProtocols, networkId?: string): Promise<AirGapBlockExplorer | undefined>;
13
+ createV3SerializerCompanion(): Promise<AirGapV3SerializerCompanion>;
14
+ private createProtocol;
15
+ }
16
+ export {};
@@ -0,0 +1,112 @@
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.BitcoinModule = void 0;
40
+ var coinlib_core_1 = require("@airgap/coinlib-core");
41
+ var errors_1 = require("@airgap/coinlib-core/errors");
42
+ var module_kit_1 = require("@airgap/module-kit");
43
+ var BlockCypherBlockExplorer_1 = require("../block-explorer/BlockCypherBlockExplorer");
44
+ var BitcoinProtocol_1 = require("../protocol/BitcoinProtocol");
45
+ var BitcoinSegwitProtocol_1 = require("../protocol/BitcoinSegwitProtocol");
46
+ var serializer_companion_1 = require("../serializer/v3/serializer-companion");
47
+ var BitcoinModule = /** @class */ (function () {
48
+ function BitcoinModule() {
49
+ var _a;
50
+ var networkRegistry = new module_kit_1.ModuleNetworkRegistry({
51
+ supportedNetworks: [BitcoinProtocol_1.BITCOIN_MAINNET_PROTOCOL_NETWORK]
52
+ });
53
+ this.networkRegistries = (_a = {},
54
+ _a[coinlib_core_1.MainProtocolSymbols.BTC] = networkRegistry,
55
+ _a[coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT] = networkRegistry,
56
+ _a);
57
+ this.supportedProtocols = (0, module_kit_1.createSupportedProtocols)(this.networkRegistries);
58
+ }
59
+ BitcoinModule.prototype.createOfflineProtocol = function (identifier) {
60
+ return __awaiter(this, void 0, void 0, function () {
61
+ return __generator(this, function (_a) {
62
+ return [2 /*return*/, this.createProtocol(identifier)];
63
+ });
64
+ });
65
+ };
66
+ BitcoinModule.prototype.createOnlineProtocol = function (identifier, networkId) {
67
+ var _a;
68
+ return __awaiter(this, void 0, void 0, function () {
69
+ var network;
70
+ return __generator(this, function (_b) {
71
+ network = (_a = this.networkRegistries[identifier]) === null || _a === void 0 ? void 0 : _a.findNetwork(networkId);
72
+ if (network === undefined) {
73
+ throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.BITCOIN, 'Protocol network not supported.');
74
+ }
75
+ return [2 /*return*/, (0, BitcoinProtocol_1.createBitcoinProtocol)({ network: network })];
76
+ });
77
+ });
78
+ };
79
+ BitcoinModule.prototype.createBlockExplorer = function (identifier, networkId) {
80
+ var _a;
81
+ return __awaiter(this, void 0, void 0, function () {
82
+ var network;
83
+ return __generator(this, function (_b) {
84
+ network = (_a = this.networkRegistries[identifier]) === null || _a === void 0 ? void 0 : _a.findNetwork(networkId);
85
+ if ((network === null || network === void 0 ? void 0 : network.type) !== 'mainnet') {
86
+ throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.BITCOIN, 'Block Explorer network not supported.');
87
+ }
88
+ return [2 /*return*/, new BlockCypherBlockExplorer_1.BlockCypherBlockExplorer()];
89
+ });
90
+ });
91
+ };
92
+ BitcoinModule.prototype.createV3SerializerCompanion = function () {
93
+ return __awaiter(this, void 0, void 0, function () {
94
+ return __generator(this, function (_a) {
95
+ return [2 /*return*/, new serializer_companion_1.BitcoinV3SerializerCompanion()];
96
+ });
97
+ });
98
+ };
99
+ BitcoinModule.prototype.createProtocol = function (identifier, network) {
100
+ switch (identifier) {
101
+ case coinlib_core_1.MainProtocolSymbols.BTC:
102
+ return (0, BitcoinProtocol_1.createBitcoinProtocol)();
103
+ case coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT:
104
+ return (0, BitcoinSegwitProtocol_1.createBitcoinSegwitProtocol)();
105
+ default:
106
+ throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.BITCOIN, "Protocol ".concat(identifier, " not supported."));
107
+ }
108
+ };
109
+ return BitcoinModule;
110
+ }());
111
+ exports.BitcoinModule = BitcoinModule;
112
+ //# sourceMappingURL=BitcoinModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitcoinModule.js","sourceRoot":"","sources":["../../../src/v1/module/BitcoinModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAkE;AAClE,sDAAqE;AACrE,iDAW2B;AAE3B,uFAAqF;AACrF,+DAAqG;AACrG,2EAA+E;AAC/E,8EAAoF;AAIpF;IAIE;;QACE,IAAM,eAAe,GAA0B,IAAI,kCAAqB,CAAC;YACvE,iBAAiB,EAAE,CAAC,kDAAgC,CAAC;SACtD,CAAC,CAAA;QACF,IAAI,CAAC,iBAAiB;YACpB,GAAC,kCAAmB,CAAC,GAAG,IAAG,eAAe;YAC1C,GAAC,kCAAmB,CAAC,UAAU,IAAG,eAAe;eAClD,CAAA;QACD,IAAI,CAAC,kBAAkB,GAAG,IAAA,qCAAwB,EAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAC5E,CAAC;IAEY,6CAAqB,GAAlC,UAAmC,UAA8B;;;gBAC/D,sBAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAA;;;KACvC;IAEY,4CAAoB,GAAjC,UAAkC,UAA8B,EAAE,SAAkB;;;;;gBAC5E,OAAO,GAAgC,MAAA,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,0CAAE,WAAW,CAAC,SAAS,CAAC,CAAA;gBACvG,IAAI,OAAO,KAAK,SAAS,EAAE;oBACzB,MAAM,IAAI,gCAAuB,CAAC,qBAAM,CAAC,OAAO,EAAE,iCAAiC,CAAC,CAAA;iBACrF;gBAED,sBAAO,IAAA,uCAAqB,EAAC,EAAE,OAAO,SAAA,EAAE,CAAC,EAAA;;;KAC1C;IAEY,2CAAmB,GAAhC,UAAiC,UAA8B,EAAE,SAAkB;;;;;gBAC3E,OAAO,GAAgC,MAAA,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,0CAAE,WAAW,CAAC,SAAS,CAAC,CAAA;gBACvG,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,SAAS,EAAE;oBAC/B,MAAM,IAAI,gCAAuB,CAAC,qBAAM,CAAC,OAAO,EAAE,uCAAuC,CAAC,CAAA;iBAC3F;gBAED,sBAAO,IAAI,mDAAwB,EAAE,EAAA;;;KACtC;IAEY,mDAA2B,GAAxC;;;gBACE,sBAAO,IAAI,mDAA4B,EAAE,EAAA;;;KAC1C;IAEO,sCAAc,GAAtB,UAAuB,UAA8B,EAAE,OAAyB;QAC9E,QAAQ,UAAU,EAAE;YAClB,KAAK,kCAAmB,CAAC,GAAG;gBAC1B,OAAO,IAAA,uCAAqB,GAAE,CAAA;YAChC,KAAK,kCAAmB,CAAC,UAAU;gBACjC,OAAO,IAAA,mDAA2B,GAAE,CAAA;YACtC;gBACE,MAAM,IAAI,gCAAuB,CAAC,qBAAM,CAAC,OAAO,EAAE,mBAAY,UAAU,oBAAiB,CAAC,CAAA;SAC7F;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AAnDD,IAmDC;AAnDY,sCAAa"}
package/v1/module.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { AirGapModule } from '@airgap/module-kit';
2
+ export * from './index';
3
+ export declare function create(): AirGapModule;
package/v1/module.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.create = void 0;
18
+ var BitcoinModule_1 = require("./module/BitcoinModule");
19
+ __exportStar(require("./index"), exports);
20
+ function create() {
21
+ return new BitcoinModule_1.BitcoinModule();
22
+ }
23
+ exports.create = create;
24
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/v1/module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,wDAAsD;AAEtD,0CAAuB;AAEvB,SAAgB,MAAM;IACpB,OAAO,IAAI,6BAAa,EAAE,CAAA;AAC5B,CAAC;AAFD,wBAEC"}
@@ -0,0 +1,12 @@
1
+ import { Secp256k1CryptoClient } from '@airgap/coinlib-core/protocols/Secp256k1CryptoClient';
2
+ import { BitcoinProtocol } from '../../v1';
3
+ import { BitcoinJS } from '../types/bitcoinjs';
4
+ export declare class BitcoinCryptoClient extends Secp256k1CryptoClient {
5
+ private readonly protocol;
6
+ private readonly bitcoinjs;
7
+ constructor(protocol: BitcoinProtocol, bitcoinjs: BitcoinJS);
8
+ signMessage(message: string, keypair: {
9
+ privateKey: string;
10
+ }): Promise<string>;
11
+ verifyMessage(message: string, signature: string, publicKey: string): Promise<boolean>;
12
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.BitcoinCryptoClient = void 0;
55
+ var Secp256k1CryptoClient_1 = require("@airgap/coinlib-core/protocols/Secp256k1CryptoClient");
56
+ var hex_1 = require("@airgap/coinlib-core/utils/hex");
57
+ var module_kit_1 = require("@airgap/module-kit");
58
+ var BitcoinCryptoClient = /** @class */ (function (_super) {
59
+ __extends(BitcoinCryptoClient, _super);
60
+ function BitcoinCryptoClient(protocol, bitcoinjs) {
61
+ var _this = _super.call(this) || this;
62
+ _this.protocol = protocol;
63
+ _this.bitcoinjs = bitcoinjs;
64
+ return _this;
65
+ }
66
+ BitcoinCryptoClient.prototype.signMessage = function (message, keypair) {
67
+ return __awaiter(this, void 0, void 0, function () {
68
+ var signature;
69
+ return __generator(this, function (_a) {
70
+ signature = this.bitcoinjs.message.sign(message, Buffer.from(keypair.privateKey, 'hex'), true);
71
+ return [2 /*return*/, signature.toString('base64')];
72
+ });
73
+ });
74
+ };
75
+ BitcoinCryptoClient.prototype.verifyMessage = function (message, signature, publicKey) {
76
+ return __awaiter(this, void 0, void 0, function () {
77
+ var rawSignature, _publicKey, address;
78
+ return __generator(this, function (_a) {
79
+ switch (_a.label) {
80
+ case 0:
81
+ rawSignature = Buffer.from(signature, 'base64');
82
+ _publicKey = (0, hex_1.isHex)(publicKey)
83
+ ? (0, module_kit_1.newPublicKey)(publicKey, 'hex')
84
+ : (0, module_kit_1.newExtendedPublicKey)(publicKey, 'encoded');
85
+ return [4 /*yield*/, this.protocol.getAddressFromPublicKey(_publicKey)];
86
+ case 1:
87
+ address = _a.sent();
88
+ return [2 /*return*/, this.bitcoinjs.message.verify(message, address, rawSignature)];
89
+ }
90
+ });
91
+ });
92
+ };
93
+ return BitcoinCryptoClient;
94
+ }(Secp256k1CryptoClient_1.Secp256k1CryptoClient));
95
+ exports.BitcoinCryptoClient = BitcoinCryptoClient;
96
+ //# sourceMappingURL=BitcoinCryptoClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitcoinCryptoClient.js","sourceRoot":"","sources":["../../../src/v1/protocol/BitcoinCryptoClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8FAA4F;AAC5F,sDAAsD;AACtD,iDAAqG;AAKrG;IAAyC,uCAAqB;IAC5D,6BAA6B,QAAyB,EAAmB,SAAoB;QAA7F,YACE,iBAAO,SACR;QAF4B,cAAQ,GAAR,QAAQ,CAAiB;QAAmB,eAAS,GAAT,SAAS,CAAW;;IAE7F,CAAC;IAEY,yCAAW,GAAxB,UAAyB,OAAe,EAAE,OAA+B;;;;gBACjE,SAAS,GAAW,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAA;gBAE5G,sBAAO,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAA;;;KACpC;IAEY,2CAAa,GAA1B,UAA2B,OAAe,EAAE,SAAiB,EAAE,SAAiB;;;;;;wBACxE,YAAY,GAAW,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;wBAGvD,UAAU,GAAkC,IAAA,WAAK,EAAC,SAAS,CAAC;4BAChE,CAAC,CAAC,IAAA,yBAAY,EAAC,SAAS,EAAE,KAAK,CAAC;4BAChC,CAAC,CAAC,IAAA,iCAAoB,EAAC,SAAS,EAAE,SAAS,CAAC,CAAA;wBAE9B,qBAAM,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC,UAAU,CAAC,EAAA;;wBAAjE,OAAO,GAAG,SAAuD;wBAEvE,sBAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,EAAA;;;;KACrE;IACH,0BAAC;AAAD,CAAC,AAvBD,CAAyC,6CAAqB,GAuB7D;AAvBY,kDAAmB"}
@@ -0,0 +1,72 @@
1
+ import { Address, AirGapProtocol, AirGapTransaction, AirGapTransactionsWithCursor, Amount, Balance, CryptoDerivative, ExtendedKeyPair, ExtendedPublicKey, ExtendedSecretKey, FeeDefaults, KeyPair, ProtocolMetadata, ProtocolUnitsMetadata, PublicKey, RecursivePartial, SecretKey, Signature, SignedTransaction, TransactionConfiguration, TransactionDetails, UnsignedTransaction } from '@airgap/module-kit';
2
+ import { BitcoinJS } from '../types/bitcoinjs';
3
+ import { BitcoinCryptoConfiguration } from '../types/crypto';
4
+ import { BitcoinProtocolNetwork, BitcoinProtocolOptions, BitcoinStandardProtocolNetwork, BitcoinUnits } from '../types/protocol';
5
+ import { BitcoinSignedTransaction, BitcoinTransactionCursor, BitcoinUnsignedTransaction } from '../types/transaction';
6
+ export interface BitcoinProtocol<_SignedTransaction extends SignedTransaction = BitcoinSignedTransaction, _UnsignedTransaction extends UnsignedTransaction = BitcoinUnsignedTransaction> extends AirGapProtocol<{
7
+ AddressResult: Address;
8
+ ProtocolNetwork: BitcoinProtocolNetwork;
9
+ CryptoConfiguration: BitcoinCryptoConfiguration;
10
+ SignedTransaction: _SignedTransaction;
11
+ TransactionCursor: BitcoinTransactionCursor;
12
+ Units: BitcoinUnits;
13
+ FeeEstimation: FeeDefaults<BitcoinUnits>;
14
+ UnsignedTransaction: _UnsignedTransaction;
15
+ }, 'Bip32', 'Crypto', 'FetchDataForAddress', 'FetchDataForMultipleAddresses'> {
16
+ }
17
+ export declare class BitcoinProtocolImpl implements BitcoinProtocol {
18
+ private readonly options;
19
+ private readonly cryptoClient;
20
+ readonly bitcoinJS: BitcoinJS;
21
+ constructor(options?: RecursivePartial<BitcoinProtocolOptions>, bitcoinJS?: any, bitcoinJSMessage?: any);
22
+ readonly units: ProtocolUnitsMetadata<BitcoinUnits>;
23
+ readonly feeDefaults: FeeDefaults<BitcoinUnits>;
24
+ readonly metadata: ProtocolMetadata<BitcoinUnits>;
25
+ getMetadata(): Promise<ProtocolMetadata<BitcoinUnits>>;
26
+ getAddressFromPublicKey(publicKey: PublicKey | ExtendedPublicKey): Promise<string>;
27
+ private getAddressFromNonExtendedPublicKey;
28
+ private getAddressFromExtendedPublicKey;
29
+ deriveFromExtendedPublicKey(extendedPublicKey: ExtendedPublicKey, visibilityIndex: number, addressIndex: number): Promise<PublicKey>;
30
+ getDetailsFromTransaction(transaction: BitcoinSignedTransaction | BitcoinUnsignedTransaction, _publicKey: PublicKey | ExtendedPublicKey): Promise<AirGapTransaction<BitcoinUnits>[]>;
31
+ private getDetailsFromSignedTransaction;
32
+ private getDetailsFromUnsignedTransaction;
33
+ verifyMessageWithPublicKey(message: string, signature: Signature, publicKey: ExtendedPublicKey | PublicKey): Promise<boolean>;
34
+ encryptAsymmetricWithPublicKey(payload: string, publicKey: ExtendedPublicKey | PublicKey): Promise<string>;
35
+ private readonly cryptoConfiguration;
36
+ getCryptoConfiguration(): Promise<BitcoinCryptoConfiguration>;
37
+ getKeyPairFromDerivative(derivative: CryptoDerivative): Promise<KeyPair>;
38
+ getExtendedKeyPairFromDerivative(derivative: CryptoDerivative): Promise<ExtendedKeyPair>;
39
+ deriveFromExtendedSecretKey(extendedSecretKey: ExtendedSecretKey, visibilityIndex: number, addressIndex: number): Promise<SecretKey>;
40
+ signTransactionWithSecretKey(transaction: BitcoinUnsignedTransaction, secretKey: SecretKey | ExtendedSecretKey): Promise<BitcoinSignedTransaction>;
41
+ private signTransactionWithNonExtendedSecretKey;
42
+ private signTransactionWithExtendedSecretKey;
43
+ private createSignedTransaction;
44
+ signMessageWithKeyPair(message: string, keyPair: ExtendedKeyPair | KeyPair): Promise<Signature>;
45
+ decryptAsymmetricWithKeyPair(payload: string, keyPair: ExtendedKeyPair | KeyPair): Promise<string>;
46
+ encryptAESWithSecretKey(payload: string, secretKey: SecretKey | ExtendedSecretKey): Promise<string>;
47
+ decryptAESWithSecretKey(payload: string, secretKey: SecretKey | ExtendedSecretKey): Promise<string>;
48
+ getNetwork(): Promise<BitcoinProtocolNetwork>;
49
+ getTransactionsForPublicKey(publicKey: ExtendedPublicKey | PublicKey, limit: number, cursor?: BitcoinTransactionCursor): Promise<AirGapTransactionsWithCursor<BitcoinTransactionCursor, BitcoinUnits>>;
50
+ private getTransactionsForNonExtendedPublicKey;
51
+ private getTransactionsForExtendedPublicKey;
52
+ getTransactionsForAddress(address: string, limit: number, cursor?: BitcoinTransactionCursor): Promise<AirGapTransactionsWithCursor<BitcoinTransactionCursor, BitcoinUnits>>;
53
+ getTransactionsForAddresses(addresses: string[], limit: number, cursor?: BitcoinTransactionCursor): Promise<AirGapTransactionsWithCursor<BitcoinTransactionCursor, BitcoinUnits>>;
54
+ getBalanceOfPublicKey(publicKey: ExtendedPublicKey | PublicKey): Promise<Balance<BitcoinUnits>>;
55
+ private getBalanceOfNonExtendedPublicKey;
56
+ private getBalanceOfExtendedPublicKey;
57
+ getBalanceOfAddress(address: string): Promise<Balance<BitcoinUnits>>;
58
+ getBalanceOfAddresses(addresses: string[]): Promise<Balance<BitcoinUnits>>;
59
+ getTransactionMaxAmountWithPublicKey(publicKey: ExtendedPublicKey | PublicKey, to: string[], configuration?: TransactionConfiguration<BitcoinUnits>): Promise<Amount<BitcoinUnits>>;
60
+ getTransactionFeeWithPublicKey(publicKey: ExtendedPublicKey | PublicKey, details: TransactionDetails<BitcoinUnits>[]): Promise<FeeDefaults<BitcoinUnits>>;
61
+ prepareTransactionWithPublicKey(publicKey: ExtendedPublicKey | PublicKey, details: TransactionDetails<BitcoinUnits>[], configuration?: TransactionConfiguration<BitcoinUnits>): Promise<BitcoinUnsignedTransaction>;
62
+ private prepareTransactionWithNonExtendedPublicKey;
63
+ private prepareTransactionWithExtendedPublicKey;
64
+ broadcastTransaction(transaction: BitcoinSignedTransaction): Promise<string>;
65
+ protected convertExtendedSecretKey(extendedSecretKey: ExtendedSecretKey, targetFormat: ExtendedSecretKey['format']): ExtendedSecretKey;
66
+ protected convertExtendedPublicKey(extendedPublicKey: ExtendedPublicKey, targetFormat: ExtendedPublicKey['format']): ExtendedPublicKey;
67
+ private convertCryptoDerivative;
68
+ private derivativeToBip32Node;
69
+ }
70
+ export declare function createBitcoinProtocol(options?: RecursivePartial<BitcoinProtocolOptions>): BitcoinProtocol;
71
+ export declare const BITCOIN_MAINNET_PROTOCOL_NETWORK: BitcoinStandardProtocolNetwork;
72
+ export declare function createBitcoinProtocolOptions(network?: Partial<BitcoinProtocolNetwork>): BitcoinProtocolOptions;