@wallfree-dev/bitcoin 0.13.42
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/LICENSE.md +7 -0
- package/index.d.ts +1 -0
- package/index.js +18 -0
- package/index.js.map +1 -0
- package/package.json +66 -0
- package/readme.md +121 -0
- 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 +168 -0
- package/v0/protocol/BitcoinProtocol.js +1070 -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 +29 -0
- package/v0/protocol/BitcoinSegwitProtocol.js +548 -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 +72 -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 +9 -0
- package/v1/data/BitcoinSegwitAddress.js +25 -0
- package/v1/data/BitcoinSegwitAddress.js.map +1 -0
- package/v1/data/BitcoinTaprootAddress.d.ts +9 -0
- package/v1/data/BitcoinTaprootAddress.js +57 -0
- package/v1/data/BitcoinTaprootAddress.js.map +1 -0
- package/v1/index.d.ts +25 -0
- package/v1/index.js +30 -0
- package/v1/index.js.map +1 -0
- package/v1/module/BitcoinModule.d.ts +18 -0
- package/v1/module/BitcoinModule.js +116 -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 +84 -0
- package/v1/protocol/BitcoinProtocol.js +1312 -0
- package/v1/protocol/BitcoinProtocol.js.map +1 -0
- package/v1/protocol/BitcoinSegwitProtocol.d.ts +56 -0
- package/v1/protocol/BitcoinSegwitProtocol.js +863 -0
- package/v1/protocol/BitcoinSegwitProtocol.js.map +1 -0
- package/v1/protocol/BitcoinTaprootProtocol.d.ts +60 -0
- package/v1/protocol/BitcoinTaprootProtocol.js +1079 -0
- package/v1/protocol/BitcoinTaprootProtocol.js.map +1 -0
- package/v1/protocol/BitcoinTestnetProtocol.d.ts +10 -0
- package/v1/protocol/BitcoinTestnetProtocol.js +70 -0
- package/v1/protocol/BitcoinTestnetProtocol.js.map +1 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +19 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +96 -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-taproot.d.ts +4 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin-taproot.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-bitcoin-taproot.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-taproot.d.ts +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin-taproot.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-bitcoin-taproot.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-taproot.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-taproot.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 +219 -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 +20 -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 +49 -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/protocol.d.ts +10 -0
- package/v1/utils/protocol.js +33 -0
- package/v1/utils/protocol.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
package/LICENSE.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2019 Papers AG
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './v1';
|
package/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
__exportStar(require("./v1"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAoB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wallfree-dev/bitcoin",
|
|
3
|
+
"version": "0.13.42",
|
|
4
|
+
"description": "The @wallfree-dev/bitcoin is a Bitcoin implementation of the ICoinProtocol interface from @wallfree-dev/coinlib-core.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"airgap",
|
|
7
|
+
"blockchain",
|
|
8
|
+
"crypto",
|
|
9
|
+
"bitcoin"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://www.airgap.it",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/airgap-it/airgap-coin-lib"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "rm -rf ./dist && tsc && node scripts/copy-files-after-build.js",
|
|
22
|
+
"build-scripts": "tsc scripts/copy-files-after-build.ts",
|
|
23
|
+
"lint": "tslint -c ./tslint.json --project ./tsconfig.json --format stylish --fix",
|
|
24
|
+
"lint:prettier": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
25
|
+
"lint-ci": "tslint -t json -o ../../lint-reports/bitcoin.json --project . || true",
|
|
26
|
+
"lint-ci:prettier": "prettier \"src/**/*.ts\" \"test/**/*.ts\" --list-different",
|
|
27
|
+
"test": "TS_NODE_PROJECT='./test/tsconfig.json' nyc mocha --bail --require ts-node/register --require tsconfig-paths/register --require source-map-support/register --full-trace --delay --timeout 40000 ./test/**/**.spec.ts",
|
|
28
|
+
"test-ci": "nyc --reporter=lcov pnpm test",
|
|
29
|
+
"browserify": "browserify ./dist/index.js -s airgapCoinLibBitcoin > ./dist/airgap-coinlib-bitcoin.min.js"
|
|
30
|
+
},
|
|
31
|
+
"author": "Papers AG <contact@papers.ch> (https://papers.ch)",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@wallfree-dev/coinlib-core": "^0.13.42",
|
|
34
|
+
"@wallfree-dev/crypto": "^0.13.42",
|
|
35
|
+
"@wallfree-dev/module-kit": "^0.13.42",
|
|
36
|
+
"@wallfree-dev/serializer": "^0.13.42",
|
|
37
|
+
"@bitcoinerlab/secp256k1": "1.2.0",
|
|
38
|
+
"bip32": "5.0.0-rc.0",
|
|
39
|
+
"bitcoinjs-lib": "6.1.7"
|
|
40
|
+
},
|
|
41
|
+
"localDependencies": {
|
|
42
|
+
"bitcoinjs-message": "2.1.1"
|
|
43
|
+
},
|
|
44
|
+
"nyc": {
|
|
45
|
+
"include": [
|
|
46
|
+
"src/**/*.ts"
|
|
47
|
+
],
|
|
48
|
+
"exclude": [
|
|
49
|
+
"test/**/*.spec.ts"
|
|
50
|
+
],
|
|
51
|
+
"extension": [
|
|
52
|
+
".ts"
|
|
53
|
+
],
|
|
54
|
+
"require": [
|
|
55
|
+
"ts-node/register"
|
|
56
|
+
],
|
|
57
|
+
"reporter": [
|
|
58
|
+
"text",
|
|
59
|
+
"text-summary"
|
|
60
|
+
],
|
|
61
|
+
"report-dir": "../../coverage/bitcoin",
|
|
62
|
+
"sourceMap": true,
|
|
63
|
+
"instrument": true
|
|
64
|
+
},
|
|
65
|
+
"gitHead": "8e8feb6788204501b7173aa825f5456c2a5f185b"
|
|
66
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# AirGap Coin Library
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/airgap-coin-lib)
|
|
4
|
+
[](https://airgap-it.github.io/airgap-coin-lib/)
|
|
5
|
+
[](https://travis-ci.org/airgap-it/airgap-coin-lib/)
|
|
6
|
+
[](https://codecov.io/gh/airgap-it/airgap-coin-lib/)
|
|
7
|
+
|
|
8
|
+
The `airgap-coin-lib` is a protocol-agnostic library that allows easy handling of the most important tasks relating cryptocurrencies and blockchains.
|
|
9
|
+
|
|
10
|
+
It implements operations such as preparing, signing and broadcasting transactions for a range of protocols.
|
|
11
|
+
|
|
12
|
+
The library consists of a shared interface for all implemented protocols. This is especially useful in the context of AirGap because methods are designed to support offline key management and signing. The following core operations are specified:
|
|
13
|
+
|
|
14
|
+
- `prepareTransaction` - This is done on AirGap Wallet (online) side. Either a public key or extended public key is used and will fetch the required information from the network.
|
|
15
|
+
- `signTransaction` - This is done in AirGap Vault (offline) side. The output of "prepareTransaction" is the input for this method (hence the output of "prepareTransaction" is transferred via URL scheme (same-device) or QR code (2-device-setup)).
|
|
16
|
+
- `broadcastTransaction` - This is done in AirGap Wallet (online) side. The output of "signTransaction" is the input for this method (hence the output of "signTransaction" is transferred via URL scheme (same-device) or QR code (2-device-setup)).
|
|
17
|
+
|
|
18
|
+
## Supported Protocols
|
|
19
|
+
|
|
20
|
+
The modular design used in this library allows you to simply add new protocols with special logic. Adding a new Bitcoin-like protocol basically means:
|
|
21
|
+
|
|
22
|
+
1. select the correct network parameters (see `src/networks.ts`)
|
|
23
|
+
2. set the Insight API URL to communicate with the blockchain
|
|
24
|
+
|
|
25
|
+
Adding a new Ethereum-like protocol means:
|
|
26
|
+
|
|
27
|
+
1. set the correct chain id
|
|
28
|
+
2. set the JSON RPC URL
|
|
29
|
+
|
|
30
|
+
Currently supported are:
|
|
31
|
+
|
|
32
|
+
- Bitcoin
|
|
33
|
+
- Ethereum
|
|
34
|
+
- Generic ERC20 Tokens
|
|
35
|
+
- Aeternity
|
|
36
|
+
- Tezos
|
|
37
|
+
- FA1.2 tokens
|
|
38
|
+
- tzBTC
|
|
39
|
+
- USDtz
|
|
40
|
+
- FA2 tokens
|
|
41
|
+
- Groestlcoin
|
|
42
|
+
- Cosmos
|
|
43
|
+
- Polkadot
|
|
44
|
+
- Kusama
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
### Protocols
|
|
49
|
+
|
|
50
|
+
The way the interface was designed is to allow stateless calls. This means the class stores very little state itself.
|
|
51
|
+
All required input comes from the method params (public key, extended public key, etc...)
|
|
52
|
+
|
|
53
|
+
Currently we support for Bitcoin-like (UTXO) protocols:
|
|
54
|
+
|
|
55
|
+
- Single Address Wallets (deprecated)
|
|
56
|
+
- HD Wallets
|
|
57
|
+
|
|
58
|
+
Currently we support for Ethereum-like (Account-based) protocols:
|
|
59
|
+
|
|
60
|
+
- Single Address Wallets
|
|
61
|
+
|
|
62
|
+
### Delegation
|
|
63
|
+
|
|
64
|
+
There is a different interface that can be implemented if the protocol supports delegation. The delegation flow usually requires some changes in the user interface of the AirGap Wallet as well.
|
|
65
|
+
|
|
66
|
+
### Inter App Communication
|
|
67
|
+
|
|
68
|
+
A serializer is included that encodes JSON structures with RLP and base58check. Those strings can then be sent to the other app, either through QR codes or a URL. The serializer can only serialize messages in predefined formats, so new message types have to be added when new protocols are added.
|
|
69
|
+
|
|
70
|
+
### Tezos FA1.2 and FA2 tokens
|
|
71
|
+
|
|
72
|
+
It is possible to interact (fetch balances, create transfers, etc.) with an FA1.2 and FA2 smart contracts using the `TezosFA12Protocol` and `TezosFA2Protocol` classes. An example on how to use them can be found in `examples/custom/protocols/tezos/fa2-smart-contract.ts`.
|
|
73
|
+
|
|
74
|
+
## Synchronising information between wallet and vault
|
|
75
|
+
|
|
76
|
+
Such that the system works we need to be able to synchronise wallets. A wallet can be:
|
|
77
|
+
|
|
78
|
+
- Single Address Wallet
|
|
79
|
+
- HD Wallet
|
|
80
|
+
|
|
81
|
+
For the single address wallet we only need to share the public key. For HD Wallet we need to share the extended public key.
|
|
82
|
+
|
|
83
|
+
## Getting started
|
|
84
|
+
|
|
85
|
+
### Requirements
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
npm >= 6
|
|
89
|
+
NodeJS >= 12
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Build dependencies get installed using `npm install`.
|
|
93
|
+
|
|
94
|
+
### Clone and Run
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
$ git clone https://github.com/airgap-it/airgap-coin-lib.git
|
|
98
|
+
$ cd airgap-coin-lib
|
|
99
|
+
$ npm install
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
To run the tests, you will have to install the test dependencies
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
$ npm run install-test-dependencies
|
|
106
|
+
$ npm test
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
To remove the test dependencies and clean up the `package.json` and `package-lock.json`, execute this command
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
$ npm run install-build-dependencies
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Contributing
|
|
116
|
+
|
|
117
|
+
We welcome contributions from the community. Simple readme updates or bugfixes can be addressed with a PR directly.
|
|
118
|
+
|
|
119
|
+
For larger changes like new protocols, new features or larger refactorings, please contact us first by opening an issue. This project is under constant development and until version `1.x.x` has been reached, there will be frequent breaking changes. So make sure to take a look at the `develop` branch.
|
|
120
|
+
|
|
121
|
+
Regarding new protocols / currencies, we cannot guarantee that they will be merged, but we're more than happy to discuss the details of a specific integration in a github issue.
|
package/v0/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BitcoinAddress } from './protocol/BitcoinAddress';
|
|
2
|
+
import { BitcoinCryptoClient } from './protocol/BitcoinCryptoClient';
|
|
3
|
+
import { BitcoinProtocol } from './protocol/BitcoinProtocol';
|
|
4
|
+
import { BitcoinProtocolConfig, BitcoinProtocolNetwork, BitcoinProtocolNetworkExtras, BitcoinProtocolOptions, BlockcypherBlockExplorer } from './protocol/BitcoinProtocolOptions';
|
|
5
|
+
import { BitcoinSegwitAddress } from './protocol/BitcoinSegwitAddress';
|
|
6
|
+
import { BitcoinSegwitProtocol } from './protocol/BitcoinSegwitProtocol';
|
|
7
|
+
import { BitcoinTestnetProtocol } from './protocol/BitcoinTestnetProtocol';
|
|
8
|
+
import { SignedBitcoinTransaction } from './types/signed-transaction-bitcoin';
|
|
9
|
+
import { SignedBitcoinSegwitTransaction } from './types/signed-transaction-bitcoin-segwit';
|
|
10
|
+
import { RawBitcoinSegwitTransaction, RawBitcoinTransaction } from './types/transaction-bitcoin';
|
|
11
|
+
import { UnsignedBitcoinTransaction } from './types/unsigned-transaction-bitcoin';
|
|
12
|
+
import { UnsignedBitcoinSegwitTransaction } from './types/unsigned-transaction-bitcoin-segwit';
|
|
13
|
+
export { BitcoinProtocol, BitcoinTestnetProtocol, BitcoinCryptoClient, BitcoinProtocolNetworkExtras, BlockcypherBlockExplorer, BitcoinProtocolNetwork, BitcoinProtocolConfig, BitcoinProtocolOptions, BitcoinAddress, RawBitcoinTransaction, UnsignedBitcoinTransaction, UnsignedBitcoinSegwitTransaction, SignedBitcoinTransaction, SignedBitcoinSegwitTransaction };
|
|
14
|
+
export { BitcoinSegwitProtocol, BitcoinSegwitAddress, RawBitcoinSegwitTransaction };
|
package/v0/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BitcoinSegwitAddress = exports.BitcoinSegwitProtocol = exports.BitcoinAddress = exports.BitcoinProtocolOptions = exports.BitcoinProtocolConfig = exports.BitcoinProtocolNetwork = exports.BlockcypherBlockExplorer = exports.BitcoinProtocolNetworkExtras = exports.BitcoinCryptoClient = exports.BitcoinTestnetProtocol = exports.BitcoinProtocol = void 0;
|
|
4
|
+
var coinlib_core_1 = require("@wallfree-dev/coinlib-core");
|
|
5
|
+
var serializer_1 = require("@wallfree-dev/serializer");
|
|
6
|
+
var BitcoinAddress_1 = require("./protocol/BitcoinAddress");
|
|
7
|
+
Object.defineProperty(exports, "BitcoinAddress", { enumerable: true, get: function () { return BitcoinAddress_1.BitcoinAddress; } });
|
|
8
|
+
var BitcoinCryptoClient_1 = require("./protocol/BitcoinCryptoClient");
|
|
9
|
+
Object.defineProperty(exports, "BitcoinCryptoClient", { enumerable: true, get: function () { return BitcoinCryptoClient_1.BitcoinCryptoClient; } });
|
|
10
|
+
var BitcoinProtocol_1 = require("./protocol/BitcoinProtocol");
|
|
11
|
+
Object.defineProperty(exports, "BitcoinProtocol", { enumerable: true, get: function () { return BitcoinProtocol_1.BitcoinProtocol; } });
|
|
12
|
+
var BitcoinProtocolOptions_1 = require("./protocol/BitcoinProtocolOptions");
|
|
13
|
+
Object.defineProperty(exports, "BitcoinProtocolConfig", { enumerable: true, get: function () { return BitcoinProtocolOptions_1.BitcoinProtocolConfig; } });
|
|
14
|
+
Object.defineProperty(exports, "BitcoinProtocolNetwork", { enumerable: true, get: function () { return BitcoinProtocolOptions_1.BitcoinProtocolNetwork; } });
|
|
15
|
+
Object.defineProperty(exports, "BitcoinProtocolNetworkExtras", { enumerable: true, get: function () { return BitcoinProtocolOptions_1.BitcoinProtocolNetworkExtras; } });
|
|
16
|
+
Object.defineProperty(exports, "BitcoinProtocolOptions", { enumerable: true, get: function () { return BitcoinProtocolOptions_1.BitcoinProtocolOptions; } });
|
|
17
|
+
Object.defineProperty(exports, "BlockcypherBlockExplorer", { enumerable: true, get: function () { return BitcoinProtocolOptions_1.BlockcypherBlockExplorer; } });
|
|
18
|
+
var BitcoinSegwitAddress_1 = require("./protocol/BitcoinSegwitAddress");
|
|
19
|
+
Object.defineProperty(exports, "BitcoinSegwitAddress", { enumerable: true, get: function () { return BitcoinSegwitAddress_1.BitcoinSegwitAddress; } });
|
|
20
|
+
var BitcoinSegwitProtocol_1 = require("./protocol/BitcoinSegwitProtocol");
|
|
21
|
+
Object.defineProperty(exports, "BitcoinSegwitProtocol", { enumerable: true, get: function () { return BitcoinSegwitProtocol_1.BitcoinSegwitProtocol; } });
|
|
22
|
+
var BitcoinTestnetProtocol_1 = require("./protocol/BitcoinTestnetProtocol");
|
|
23
|
+
Object.defineProperty(exports, "BitcoinTestnetProtocol", { enumerable: true, get: function () { return BitcoinTestnetProtocol_1.BitcoinTestnetProtocol; } });
|
|
24
|
+
var transaction_validator_1 = require("./serializer/validators/transaction-validator");
|
|
25
|
+
// Serializer
|
|
26
|
+
serializer_1.SerializerV3.addSchema(serializer_1.IACMessageType.TransactionSignRequest, { schema: require('./serializer/schemas/v3/transaction-sign-request-bitcoin-segwit.json') }, coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT);
|
|
27
|
+
serializer_1.SerializerV3.addSchema(serializer_1.IACMessageType.TransactionSignResponse, { schema: require('./serializer/schemas/v3/transaction-sign-response-bitcoin-segwit.json') }, coinlib_core_1.MainProtocolSymbols.BTC_SEGWIT);
|
|
28
|
+
serializer_1.Serializer.addSchema(serializer_1.IACMessageType.TransactionSignRequest, { schema: require('./serializer/schemas/v2/transaction-sign-request-bitcoin.json') }, coinlib_core_1.MainProtocolSymbols.BTC);
|
|
29
|
+
serializer_1.Serializer.addSchema(serializer_1.IACMessageType.TransactionSignResponse, { schema: require('./serializer/schemas/v2/transaction-sign-response-bitcoin.json') }, coinlib_core_1.MainProtocolSymbols.BTC);
|
|
30
|
+
serializer_1.SerializerV3.addSchema(serializer_1.IACMessageType.TransactionSignRequest, { schema: require('./serializer/schemas/v3/transaction-sign-request-bitcoin.json') }, coinlib_core_1.MainProtocolSymbols.BTC);
|
|
31
|
+
serializer_1.SerializerV3.addSchema(serializer_1.IACMessageType.TransactionSignResponse, { schema: require('./serializer/schemas/v3/transaction-sign-response-bitcoin.json') }, coinlib_core_1.MainProtocolSymbols.BTC);
|
|
32
|
+
serializer_1.Serializer.addValidator(coinlib_core_1.MainProtocolSymbols.BTC, new transaction_validator_1.BitcoinTransactionValidatorFactoryV2());
|
|
33
|
+
serializer_1.SerializerV3.addValidator(coinlib_core_1.MainProtocolSymbols.BTC, new transaction_validator_1.BitcoinTransactionValidatorFactory());
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
package/v0/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v0/index.ts"],"names":[],"mappings":";;;AAAA,2DAAgE;AAChE,uDAAmF;AAEnF,4DAA0D;AA6BxD,+FA7BO,+BAAc,OA6BP;AA5BhB,sEAAoE;AAsBlE,oGAtBO,yCAAmB,OAsBP;AArBrB,8DAA4D;AAmB1D,gGAnBO,iCAAe,OAmBP;AAlBjB,4EAM0C;AAkBxC,sGAvBA,8CAAqB,OAuBA;AADrB,uGArBA,+CAAsB,OAqBA;AAFtB,6GAlBA,qDAA4B,OAkBA;AAI5B,uGArBA,+CAAsB,OAqBA;AAHtB,yGAjBA,iDAAwB,OAiBA;AAf1B,wEAAsE;AA4BtC,qGA5BvB,2CAAoB,OA4BuB;AA3BpD,0EAAwE;AA2B/D,sGA3BA,6CAAqB,OA2BA;AA1B9B,4EAA0E;AAUxE,uGAVO,+CAAsB,OAUP;AATxB,uFAAwI;AA2BxI,aAAa;AAEb,yBAAY,CAAC,SAAS,CACpB,2BAAc,CAAC,sBAAsB,EACrC,EAAE,MAAM,EAAE,OAAO,CAAC,sEAAsE,CAAC,EAAE,EAC3F,kCAAmB,CAAC,UAAU,CAC/B,CAAA;AACD,yBAAY,CAAC,SAAS,CACpB,2BAAc,CAAC,uBAAuB,EACtC,EAAE,MAAM,EAAE,OAAO,CAAC,uEAAuE,CAAC,EAAE,EAC5F,kCAAmB,CAAC,UAAU,CAC/B,CAAA;AAED,uBAAU,CAAC,SAAS,CAClB,2BAAc,CAAC,sBAAsB,EACrC,EAAE,MAAM,EAAE,OAAO,CAAC,+DAA+D,CAAC,EAAE,EACpF,kCAAmB,CAAC,GAAG,CACxB,CAAA;AACD,uBAAU,CAAC,SAAS,CAClB,2BAAc,CAAC,uBAAuB,EACtC,EAAE,MAAM,EAAE,OAAO,CAAC,gEAAgE,CAAC,EAAE,EACrF,kCAAmB,CAAC,GAAG,CACxB,CAAA;AAED,yBAAY,CAAC,SAAS,CACpB,2BAAc,CAAC,sBAAsB,EACrC,EAAE,MAAM,EAAE,OAAO,CAAC,+DAA+D,CAAC,EAAE,EACpF,kCAAmB,CAAC,GAAG,CACxB,CAAA;AACD,yBAAY,CAAC,SAAS,CACpB,2BAAc,CAAC,uBAAuB,EACtC,EAAE,MAAM,EAAE,OAAO,CAAC,gEAAgE,CAAC,EAAE,EACrF,kCAAmB,CAAC,GAAG,CACxB,CAAA;AAED,uBAAU,CAAC,YAAY,CAAC,kCAAmB,CAAC,GAAG,EAAE,IAAI,4DAAoC,EAAE,CAAC,CAAA;AAC5F,yBAAY,CAAC,YAAY,CAAC,kCAAmB,CAAC,GAAG,EAAE,IAAI,0DAAkC,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IAirGapAddress } from '@wallfree-dev/coinlib-core/interfaces/IAirGapAddress';
|
|
2
|
+
export declare class BitcoinAddress implements IAirGapAddress {
|
|
3
|
+
protected readonly value: string;
|
|
4
|
+
readonly visibilityDerivationIndex?: number | undefined;
|
|
5
|
+
readonly addressDerivationIndex?: number | undefined;
|
|
6
|
+
constructor(value: string, visibilityDerivationIndex?: number | undefined, addressDerivationIndex?: number | undefined);
|
|
7
|
+
static from(node: any, visibilityDerivationIndex?: number, addressDerivationIndex?: number): BitcoinAddress;
|
|
8
|
+
asString(): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BitcoinAddress = void 0;
|
|
4
|
+
var BitcoinAddress = /** @class */ (function () {
|
|
5
|
+
// TODO: types
|
|
6
|
+
function BitcoinAddress(value, visibilityDerivationIndex, addressDerivationIndex) {
|
|
7
|
+
this.value = value;
|
|
8
|
+
this.visibilityDerivationIndex = visibilityDerivationIndex;
|
|
9
|
+
this.addressDerivationIndex = addressDerivationIndex;
|
|
10
|
+
}
|
|
11
|
+
BitcoinAddress.from = function (node, visibilityDerivationIndex, addressDerivationIndex) {
|
|
12
|
+
var _node = visibilityDerivationIndex !== undefined && addressDerivationIndex !== undefined
|
|
13
|
+
? node.derive(visibilityDerivationIndex).derive(addressDerivationIndex)
|
|
14
|
+
: node;
|
|
15
|
+
return new BitcoinAddress(_node.getAddress(), visibilityDerivationIndex, addressDerivationIndex);
|
|
16
|
+
};
|
|
17
|
+
BitcoinAddress.prototype.asString = function () {
|
|
18
|
+
return this.value;
|
|
19
|
+
};
|
|
20
|
+
return BitcoinAddress;
|
|
21
|
+
}());
|
|
22
|
+
exports.BitcoinAddress = BitcoinAddress;
|
|
23
|
+
//# sourceMappingURL=BitcoinAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitcoinAddress.js","sourceRoot":"","sources":["../../../src/v0/protocol/BitcoinAddress.ts"],"names":[],"mappings":";;;AAEA;IACE,cAAc;IACd,wBACqB,KAAa,EAChB,yBAAkC,EAClC,sBAA+B;QAF5B,UAAK,GAAL,KAAK,CAAQ;QAChB,8BAAyB,GAAzB,yBAAyB,CAAS;QAClC,2BAAsB,GAAtB,sBAAsB,CAAS;IAC9C,CAAC;IAEU,mBAAI,GAAlB,UAAmB,IAAS,EAAE,yBAAkC,EAAE,sBAA+B;QAC/F,IAAM,KAAK,GACT,yBAAyB,KAAK,SAAS,IAAI,sBAAsB,KAAK,SAAS;YAC7E,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC,MAAM,CAAC,sBAAsB,CAAC;YACvE,CAAC,CAAC,IAAI,CAAA;QAEV,OAAO,IAAI,cAAc,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,yBAAyB,EAAE,sBAAsB,CAAC,CAAA;IAClG,CAAC;IAEM,iCAAQ,GAAf;QACE,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IACH,qBAAC;AAAD,CAAC,AApBD,IAoBC;AApBY,wCAAc"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ICoinProtocol } from '@wallfree-dev/coinlib-core';
|
|
2
|
+
import { Secp256k1CryptoClient } from '@wallfree-dev/coinlib-core/protocols/Secp256k1CryptoClient';
|
|
3
|
+
export declare class BitcoinCryptoClient extends Secp256k1CryptoClient {
|
|
4
|
+
private readonly protocol;
|
|
5
|
+
private readonly bitcoinJSMessage;
|
|
6
|
+
constructor(protocol: ICoinProtocol, bitcoinJSMessage: any);
|
|
7
|
+
signMessage(message: string, keypair: {
|
|
8
|
+
privateKey: string;
|
|
9
|
+
}): Promise<string>;
|
|
10
|
+
verifyMessage(message: string, signature: string, publicKey: string): Promise<boolean>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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("@wallfree-dev/coinlib-core/protocols/Secp256k1CryptoClient");
|
|
56
|
+
var BitcoinCryptoClient = /** @class */ (function (_super) {
|
|
57
|
+
__extends(BitcoinCryptoClient, _super);
|
|
58
|
+
function BitcoinCryptoClient(protocol, bitcoinJSMessage) {
|
|
59
|
+
var _this = _super.call(this) || this;
|
|
60
|
+
_this.protocol = protocol;
|
|
61
|
+
_this.bitcoinJSMessage = bitcoinJSMessage;
|
|
62
|
+
return _this;
|
|
63
|
+
}
|
|
64
|
+
BitcoinCryptoClient.prototype.signMessage = function (message, keypair) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var signature;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
signature = this.bitcoinJSMessage.sign(message, Buffer.from(keypair.privateKey, 'hex'), true);
|
|
69
|
+
return [2 /*return*/, signature.toString('base64')];
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
BitcoinCryptoClient.prototype.verifyMessage = function (message, signature, publicKey) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var rawSignature, address;
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
switch (_a.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
rawSignature = Buffer.from(signature, 'base64');
|
|
80
|
+
return [4 /*yield*/, this.protocol.getAddressFromPublicKey(publicKey)];
|
|
81
|
+
case 1:
|
|
82
|
+
address = _a.sent();
|
|
83
|
+
return [2 /*return*/, this.bitcoinJSMessage.verify(message, address.address, rawSignature)];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return BitcoinCryptoClient;
|
|
89
|
+
}(Secp256k1CryptoClient_1.Secp256k1CryptoClient));
|
|
90
|
+
exports.BitcoinCryptoClient = BitcoinCryptoClient;
|
|
91
|
+
//# sourceMappingURL=BitcoinCryptoClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitcoinCryptoClient.js","sourceRoot":"","sources":["../../../src/v0/protocol/BitcoinCryptoClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oGAAkG;AAElG;IAAyC,uCAAqB;IAC5D,6BAA6B,QAAuB,EAAmB,gBAAqB;QAA5F,YACE,iBAAO,SACR;QAF4B,cAAQ,GAAR,QAAQ,CAAe;QAAmB,sBAAgB,GAAhB,gBAAgB,CAAK;;IAE5F,CAAC;IAEY,yCAAW,GAAxB,UAAyB,OAAe,EAAE,OAA+B;;;;gBACjE,SAAS,GAAW,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAA;gBAE3G,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;wBAE7C,qBAAM,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,EAAA;;wBAAhE,OAAO,GAAG,SAAsD;wBAEtE,sBAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,EAAA;;;;KAC5E;IACH,0BAAC;AAAD,CAAC,AAlBD,CAAyC,6CAAqB,GAkB7D;AAlBY,kDAAmB"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { UnsignedTransaction } from '@wallfree-dev/coinlib-core';
|
|
2
|
+
import { IAirGapSignedTransaction } from '@wallfree-dev/coinlib-core/interfaces/IAirGapSignedTransaction';
|
|
3
|
+
import { AirGapTransactionStatus, IAirGapTransaction } from '@wallfree-dev/coinlib-core/interfaces/IAirGapTransaction';
|
|
4
|
+
import { CurrencyUnit, FeeDefaults, ICoinProtocol } from '@wallfree-dev/coinlib-core/protocols/ICoinProtocol';
|
|
5
|
+
import { ICoinSubProtocol } from '@wallfree-dev/coinlib-core/protocols/ICoinSubProtocol';
|
|
6
|
+
import { ProtocolSymbols } from '@wallfree-dev/coinlib-core/utils/ProtocolSymbols';
|
|
7
|
+
import { SignedBitcoinTransaction } from '../types/signed-transaction-bitcoin';
|
|
8
|
+
import { RawBitcoinTransaction } from '../types/transaction-bitcoin';
|
|
9
|
+
import { BitcoinCryptoClient } from './BitcoinCryptoClient';
|
|
10
|
+
import { BitcoinProtocolOptions } from './BitcoinProtocolOptions';
|
|
11
|
+
import { BitcoinAddressCursor, BitcoinAddressResult, BitcoinBlockbookTransactionCursor, BitcoinBlockbookTransactionResult } from './BitcoinTypes';
|
|
12
|
+
export interface UTXOResponse {
|
|
13
|
+
txid: string;
|
|
14
|
+
vout: number;
|
|
15
|
+
value: string;
|
|
16
|
+
height: number;
|
|
17
|
+
confirmations: number;
|
|
18
|
+
address: string;
|
|
19
|
+
path: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Vin {
|
|
22
|
+
txid: string;
|
|
23
|
+
sequence: any;
|
|
24
|
+
n: number;
|
|
25
|
+
addresses: string[];
|
|
26
|
+
value: string;
|
|
27
|
+
hex: string;
|
|
28
|
+
}
|
|
29
|
+
export interface Vout {
|
|
30
|
+
value: string;
|
|
31
|
+
n: number;
|
|
32
|
+
hex: string;
|
|
33
|
+
addresses: string[];
|
|
34
|
+
spent?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface Transaction {
|
|
37
|
+
txid: string;
|
|
38
|
+
version: number;
|
|
39
|
+
vin: Vin[];
|
|
40
|
+
vout: Vout[];
|
|
41
|
+
blockhash: string;
|
|
42
|
+
blockHeight: number;
|
|
43
|
+
confirmations: number;
|
|
44
|
+
blockTime: number;
|
|
45
|
+
value: string;
|
|
46
|
+
valueIn: string;
|
|
47
|
+
fees: string;
|
|
48
|
+
hex: string;
|
|
49
|
+
}
|
|
50
|
+
export interface Token {
|
|
51
|
+
type: string;
|
|
52
|
+
name: string;
|
|
53
|
+
path: string;
|
|
54
|
+
transfers: number;
|
|
55
|
+
decimals: number;
|
|
56
|
+
balance: string;
|
|
57
|
+
totalReceived: string;
|
|
58
|
+
totalSent: string;
|
|
59
|
+
}
|
|
60
|
+
export interface XPubResponse {
|
|
61
|
+
page: number;
|
|
62
|
+
totalPages: number;
|
|
63
|
+
itemsOnPage: number;
|
|
64
|
+
address: string;
|
|
65
|
+
balance: string;
|
|
66
|
+
totalReceived: string;
|
|
67
|
+
totalSent: string;
|
|
68
|
+
unconfirmedBalance: string;
|
|
69
|
+
unconfirmedTxs: number;
|
|
70
|
+
txs: number;
|
|
71
|
+
transactions?: Transaction[];
|
|
72
|
+
totalTokens?: number;
|
|
73
|
+
tokens?: Token[];
|
|
74
|
+
}
|
|
75
|
+
export interface AddressResponse {
|
|
76
|
+
page: number;
|
|
77
|
+
totalPages: number;
|
|
78
|
+
itemsOnPage: number;
|
|
79
|
+
address: string;
|
|
80
|
+
balance: string;
|
|
81
|
+
totalReceived: string;
|
|
82
|
+
totalSent: string;
|
|
83
|
+
unconfirmedBalance: string;
|
|
84
|
+
unconfirmedTxs: number;
|
|
85
|
+
txs: number;
|
|
86
|
+
transactions?: Transaction[];
|
|
87
|
+
}
|
|
88
|
+
export declare class BitcoinProtocol implements ICoinProtocol {
|
|
89
|
+
readonly options: BitcoinProtocolOptions;
|
|
90
|
+
symbol: string;
|
|
91
|
+
name: string;
|
|
92
|
+
marketSymbol: string;
|
|
93
|
+
feeSymbol: string;
|
|
94
|
+
feeDefaults: FeeDefaults;
|
|
95
|
+
decimals: number;
|
|
96
|
+
feeDecimals: number;
|
|
97
|
+
identifier: ProtocolSymbols;
|
|
98
|
+
units: CurrencyUnit[];
|
|
99
|
+
supportsHD: boolean;
|
|
100
|
+
standardDerivationPath: string;
|
|
101
|
+
addressIsCaseSensitive: boolean;
|
|
102
|
+
addressValidationPattern: string;
|
|
103
|
+
addressPlaceholder: string;
|
|
104
|
+
readonly cryptoClient: BitcoinCryptoClient;
|
|
105
|
+
constructor(options?: BitcoinProtocolOptions);
|
|
106
|
+
getSymbol(): Promise<string>;
|
|
107
|
+
getName(): Promise<string>;
|
|
108
|
+
getMarketSymbol(): Promise<string>;
|
|
109
|
+
getAssetSymbol(): Promise<string | undefined>;
|
|
110
|
+
getFeeSymbol(): Promise<string>;
|
|
111
|
+
getFeeDefaults(): Promise<FeeDefaults>;
|
|
112
|
+
getDecimals(): Promise<number>;
|
|
113
|
+
getFeeDecimals(): Promise<number>;
|
|
114
|
+
getIdentifier(): Promise<ProtocolSymbols>;
|
|
115
|
+
getUnits(): Promise<CurrencyUnit[]>;
|
|
116
|
+
getSupportsHD(): Promise<boolean>;
|
|
117
|
+
getStandardDerivationPath(): Promise<string>;
|
|
118
|
+
getAddressIsCaseSensitive(): Promise<boolean>;
|
|
119
|
+
getAddressValidationPattern(): Promise<string>;
|
|
120
|
+
getAddressPlaceholder(): Promise<string>;
|
|
121
|
+
getOptions(): Promise<BitcoinProtocolOptions>;
|
|
122
|
+
getBlockExplorerLinkForAddress(address: string): Promise<string>;
|
|
123
|
+
getBlockExplorerLinkForTxId(txId: string): Promise<string>;
|
|
124
|
+
getPublicKeyFromMnemonic(mnemonic: string, derivationPath: string, password?: string): Promise<string>;
|
|
125
|
+
getPrivateKeyFromMnemonic(mnemonic: string, derivationPath: string, password?: string): Promise<string>;
|
|
126
|
+
getExtendedPublicKeyFromMnemonic(mnemonic: string, derivationPath: string, password?: string | undefined): Promise<string>;
|
|
127
|
+
getExtendedPrivateKeyFromMnemonic(mnemonic: string, derivationPath: string, password?: string): Promise<string>;
|
|
128
|
+
getPublicKeyFromHexSecret(secret: string, derivationPath: string): Promise<string>;
|
|
129
|
+
getPrivateKeyFromHexSecret(secret: string, derivationPath: string): Promise<string>;
|
|
130
|
+
getExtendedPublicKeyFromHexSecret(secret: string, derivationPath: string): Promise<string>;
|
|
131
|
+
getExtendedPrivateKeyFromHexSecret(secret: string, derivationPath: string): Promise<string>;
|
|
132
|
+
getAddressFromPublicKey(publicKey: string, cursor?: BitcoinAddressCursor): Promise<BitcoinAddressResult>;
|
|
133
|
+
getAddressesFromPublicKey(publicKey: string, cursor?: BitcoinAddressCursor): Promise<BitcoinAddressResult[]>;
|
|
134
|
+
getAddressFromExtendedPublicKey(extendedPublicKey: string, visibilityDerivationIndex: number, addressDerivationIndex: number): Promise<BitcoinAddressResult>;
|
|
135
|
+
getAddressesFromExtendedPublicKey(extendedPublicKey: string, visibilityDerivationIndex: number, addressCount: number, offset: number): Promise<BitcoinAddressResult[]>;
|
|
136
|
+
signWithPrivateKey(privateKey: string, transaction: RawBitcoinTransaction): Promise<IAirGapSignedTransaction>;
|
|
137
|
+
signWithExtendedPrivateKey(extendedPrivateKey: string, transaction: RawBitcoinTransaction): Promise<string>;
|
|
138
|
+
getTransactionDetails(unsignedTx: UnsignedTransaction): Promise<IAirGapTransaction[]>;
|
|
139
|
+
getTransactionDetailsFromSigned(signedTx: SignedBitcoinTransaction): Promise<IAirGapTransaction[]>;
|
|
140
|
+
getBalanceOfAddresses(addresses: string[]): Promise<string>;
|
|
141
|
+
getBalanceOfPublicKey(publicKey: string): Promise<string>;
|
|
142
|
+
getBalanceOfExtendedPublicKey(extendedPublicKey: string, offset?: number): Promise<string>;
|
|
143
|
+
getBalanceOfPublicKeyForSubProtocols(publicKey: string, subProtocols: ICoinSubProtocol[]): Promise<string[]>;
|
|
144
|
+
getAvailableBalanceOfAddresses(addresses: string[]): Promise<string>;
|
|
145
|
+
estimateMaxTransactionValueFromExtendedPublicKey(extendedPublicKey: string, recipients: string[], fee?: string): Promise<string>;
|
|
146
|
+
estimateMaxTransactionValueFromPublicKey(publicKey: string, recipients: string[], fee?: string): Promise<string>;
|
|
147
|
+
estimateFeeDefaultsFromExtendedPublicKey(publicKey: string, recipients: string[], values: string[], data?: any): Promise<FeeDefaults>;
|
|
148
|
+
estimateFeeDefaultsFromPublicKey(publicKey: string, recipients: string[], values: string[], data?: any): Promise<FeeDefaults>;
|
|
149
|
+
prepareTransactionFromExtendedPublicKey(extendedPublicKey: string, offset: number, recipients: string[], values: string[], fee: string, extras: unknown): Promise<RawBitcoinTransaction>;
|
|
150
|
+
prepareTransactionFromPublicKey(publicKey: string, recipients: string[], values: string[], fee: string): Promise<RawBitcoinTransaction>;
|
|
151
|
+
broadcastTransaction(rawTransaction: string): Promise<string>;
|
|
152
|
+
getTransactionsFromExtendedPublicKey(extendedPublicKey: string, limit: number, cursor?: BitcoinBlockbookTransactionCursor, addressOffset?: number): Promise<BitcoinBlockbookTransactionResult>;
|
|
153
|
+
getTransactionsFromPublicKey(publicKey: string, limit: number, cursor?: BitcoinBlockbookTransactionCursor): Promise<BitcoinBlockbookTransactionResult>;
|
|
154
|
+
getTransactionsFromAddresses(addresses: string[], limit: number, cursor?: BitcoinBlockbookTransactionCursor): Promise<BitcoinBlockbookTransactionResult>;
|
|
155
|
+
private containsSome;
|
|
156
|
+
signMessage(message: string, keypair: {
|
|
157
|
+
privateKey: string;
|
|
158
|
+
}): Promise<string>;
|
|
159
|
+
verifyMessage(message: string, signature: string, publicKey: string): Promise<boolean>;
|
|
160
|
+
encryptAsymmetric(message: string, publicKey: string): Promise<string>;
|
|
161
|
+
decryptAsymmetric(message: string, keypair: {
|
|
162
|
+
publicKey: string;
|
|
163
|
+
privateKey: string;
|
|
164
|
+
}): Promise<string>;
|
|
165
|
+
encryptAES(message: string, privateKey: string): Promise<string>;
|
|
166
|
+
decryptAES(message: string, privateKey: string): Promise<string>;
|
|
167
|
+
getTransactionStatuses(transactionHashes: string[]): Promise<AirGapTransactionStatus[]>;
|
|
168
|
+
}
|